comparison mod_register_web/mod_register_web.lua @ 1235:9277e0a3922f

mod_register_web: Support additional registration fields
author Kim Alvefur <zash@zash.se>
date Sat, 30 Nov 2013 22:59:27 +0100
parents da39ba4047a7
children 59332e0bfbdc
comparison
equal deleted inserted replaced
1234:da39ba4047a7 1235:9277e0a3922f
1 local captcha_options = module:get_option("captcha_options", {}); 1 local captcha_options = module:get_option("captcha_options", {});
2 local nodeprep = require "util.encodings".stringprep.nodeprep; 2 local nodeprep = require "util.encodings".stringprep.nodeprep;
3 local usermanager = require "core.usermanager"; 3 local usermanager = require "core.usermanager";
4 local http = require "util.http"; 4 local http = require "util.http";
5
6 local extra_fields = {
7 nick = true; name = true; first = true; last = true; email = true;
8 address = true; city = true; state = true; zip = true;
9 phone = true; url = true; date = true;
10 }
5 11
6 function template(data) 12 function template(data)
7 -- Like util.template, but deals with plain text 13 -- Like util.template, but deals with plain text
8 return { apply = function(values) return (data:gsub("{([^}]+)}", values)); end } 14 return { apply = function(values) return (data:gsub("{([^}]+)}", values)); end }
9 end 15 end
108 if usermanager.user_exists(prepped_username, module.host) then 114 if usermanager.user_exists(prepped_username, module.host) then
109 return nil, "Username already taken"; 115 return nil, "Username already taken";
110 end 116 end
111 local ok, err = usermanager.create_user(prepped_username, form.password, module.host); 117 local ok, err = usermanager.create_user(prepped_username, form.password, module.host);
112 if ok then 118 if ok then
119 local extra_data = {};
120 for field in pairs(extra_fields) do
121 local field_value = form[field];
122 if field_value and #field_value > 0 then
123 extra_data[field] = field_value;
124 end
125 end
126 if next(first) ~= nil then
127 datamanager.store(prepped_username, module.host, "account_details", extra_data);
128 end
113 module:fire_event("user-registered", { 129 module:fire_event("user-registered", {
114 username = prepped_username, 130 username = prepped_username,
115 host = module.host, 131 host = module.host,
116 source = module.name 132 source = module.name
117 }); 133 });