Mercurial > prosody-modules
comparison mod_register_web/mod_register_web.lua @ 1320:e670d4cc5027
mod_register_web: Pass request around so IP address can be reported
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 26 Feb 2014 20:15:41 +0100 |
parents | 34fbe58d19da |
children | 742f3dc601b5 |
comparison
equal
deleted
inserted
replaced
1319:400a7fdd2049 | 1320:e670d4cc5027 |
---|---|
104 notice = display_options and display_options.register_error or ""; | 104 notice = display_options and display_options.register_error or ""; |
105 captcha = generate_captcha(display_options); | 105 captcha = generate_captcha(display_options); |
106 }) | 106 }) |
107 end | 107 end |
108 | 108 |
109 function register_user(form) | 109 function register_user(form, origin) |
110 local prepped_username = nodeprep(form.username); | 110 local prepped_username = nodeprep(form.username); |
111 if not prepped_username then | 111 if not prepped_username then |
112 return nil, "Username contains forbidden characters"; | 112 return nil, "Username contains forbidden characters"; |
113 end | 113 end |
114 if #prepped_username == 0 then | 114 if #prepped_username == 0 then |
135 datamanager.store(prepped_username, module.host, "account_details", extra_data); | 135 datamanager.store(prepped_username, module.host, "account_details", extra_data); |
136 end | 136 end |
137 module:fire_event("user-registered", { | 137 module:fire_event("user-registered", { |
138 username = prepped_username, | 138 username = prepped_username, |
139 host = module.host, | 139 host = module.host, |
140 source = module.name | 140 source = module.name, |
141 ip = origin.conn:ip(), | |
141 }); | 142 }); |
142 end | 143 end |
143 return ok, err; | 144 return ok, err; |
144 end | 145 end |
145 | 146 |
159 function handle_form(event) | 160 function handle_form(event) |
160 local request, response = event.request, event.response; | 161 local request, response = event.request, event.response; |
161 local form = http.formdecode(request.body); | 162 local form = http.formdecode(request.body); |
162 verify_captcha(request, form, function (ok, err) | 163 verify_captcha(request, form, function (ok, err) |
163 if ok then | 164 if ok then |
164 local register_ok, register_err = register_user(form); | 165 local register_ok, register_err = register_user(form, request); |
165 response:send(generate_register_response(event, form, register_ok, register_err)); | 166 response:send(generate_register_response(event, form, register_ok, register_err)); |
166 else | 167 else |
167 response:send(generate_page(event, { register_error = err })); | 168 response:send(generate_page(event, { register_error = err })); |
168 end | 169 end |
169 end); | 170 end); |