Software /
code /
prosody-modules
Comparison
mod_http_pep_avatar/mod_http_pep_avatar.lua @ 3433:213679266dcb
mod_http_pep_avatar: Redirect to prepped username
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 06 Jan 2019 10:26:32 +0100 |
parent | 3425:461429e0db58 |
child | 3575:00bdecb12779 |
comparison
equal
deleted
inserted
replaced
3432:61368aec97d6 | 3433:213679266dcb |
---|---|
4 local mod_pep = module:depends"pep"; | 4 local mod_pep = module:depends"pep"; |
5 | 5 |
6 local um = require "core.usermanager"; | 6 local um = require "core.usermanager"; |
7 local nodeprep = require "util.encodings".stringprep.nodeprep; | 7 local nodeprep = require "util.encodings".stringprep.nodeprep; |
8 local base64_decode = require "util.encodings".base64.decode; | 8 local base64_decode = require "util.encodings".base64.decode; |
9 local urlencode = require "util.http".urlencode; | |
9 | 10 |
10 module:depends("http") | 11 module:depends("http") |
11 module:provides("http", { | 12 module:provides("http", { |
12 route = { | 13 route = { |
13 ["GET /*"] = function (event, user) | 14 ["GET /*"] = function (event, user) |
14 local request, response = event.request, event.response; | 15 local request, response = event.request, event.response; |
15 local actor = request.ip; | 16 local actor = request.ip; |
16 | 17 |
17 user = nodeprep(user); | 18 local prepped = nodeprep(user); |
18 if not user then return 400; end | 19 if not prepped then return 400; end |
20 if prepped ~= user then | |
21 response.headers.location = module:http_url() .. "/" .. urlencode(prepped); | |
22 return 302; | |
23 end | |
19 if not um.user_exists(user, module.host) then | 24 if not um.user_exists(user, module.host) then |
20 return 404; | 25 return 404; |
21 end | 26 end |
22 | 27 |
23 local pep_service = mod_pep.get_pep_service(user); | 28 local pep_service = mod_pep.get_pep_service(user); |