Comparison

plugins/mod_register_ibr.lua @ 10434:8f709577fe8e

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 23 Nov 2019 23:12:01 +0100
parent 10368:76eb79d372de
child 10767:a0166932479f
comparison
equal deleted inserted replaced
10433:7777f25d5266 10434:8f709577fe8e
23 end); 23 end);
24 24
25 local account_details = module:open_store("account_details"); 25 local account_details = module:open_store("account_details");
26 26
27 local field_map = { 27 local field_map = {
28 FORM_TYPE = { name = "FORM_TYPE", type = "hidden", value = "jabber:iq:register" };
28 username = { name = "username", type = "text-single", label = "Username", required = true }; 29 username = { name = "username", type = "text-single", label = "Username", required = true };
29 password = { name = "password", type = "text-private", label = "Password", required = true }; 30 password = { name = "password", type = "text-private", label = "Password", required = true };
30 nick = { name = "nick", type = "text-single", label = "Nickname" }; 31 nick = { name = "nick", type = "text-single", label = "Nickname" };
31 name = { name = "name", type = "text-single", label = "Full Name" }; 32 name = { name = "name", type = "text-single", label = "Full Name" };
32 first = { name = "first", type = "text-single", label = "Given Name" }; 33 first = { name = "first", type = "text-single", label = "Given Name" };
48 49
49 local registration_form = dataform_new{ 50 local registration_form = dataform_new{
50 title = title; 51 title = title;
51 instructions = instructions; 52 instructions = instructions;
52 53
54 field_map.FORM_TYPE;
53 field_map.username; 55 field_map.username;
54 field_map.password; 56 field_map.password;
55 }; 57 };
56 58
57 local registration_query = st.stanza("query", {xmlns = "jabber:iq:register"}) 59 local registration_query = st.stanza("query", {xmlns = "jabber:iq:register"})
151 end 153 end
152 session.send(st.error_reply(stanza, "modify", "not-acceptable", table.concat(textual_errors, "\n"))); 154 session.send(st.error_reply(stanza, "modify", "not-acceptable", table.concat(textual_errors, "\n")));
153 return true; 155 return true;
154 end 156 end
155 157
156 local username, password = nodeprep(data.username), data.password; 158 local username, password = nodeprep(data.username, true), data.password;
157 data.username, data.password = nil, nil; 159 data.username, data.password = nil, nil;
158 local host = module.host; 160 local host = module.host;
159 if not username or username == "" then 161 if not username or username == "" then
160 log("debug", "The requested username is invalid."); 162 log("debug", "The requested username is invalid.");
161 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid.")); 163 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid."));
164 166
165 local user = { username = username, password = password, host = host, additional = data, ip = session.ip, session = session, allowed = true } 167 local user = { username = username, password = password, host = host, additional = data, ip = session.ip, session = session, allowed = true }
166 module:fire_event("user-registering", user); 168 module:fire_event("user-registering", user);
167 if not user.allowed then 169 if not user.allowed then
168 log("debug", "Registration disallowed by module: %s", user.reason or "no reason given"); 170 log("debug", "Registration disallowed by module: %s", user.reason or "no reason given");
169 session.send(st.error_reply(stanza, "modify", "not-acceptable", user.reason)); 171 local error_type, error_condition, reason;
172 local err = user.error;
173 if err then
174 error_type, error_condition, reason = err.type, err.condition, err.text;
175 else
176 -- COMPAT pre-util.error
177 error_type, error_condition, reason = user.error_type, user.error_condition, user.reason;
178 end
179 session.send(st.error_reply(stanza, error_type or "modify", error_condition or "not-acceptable", reason));
170 return true; 180 return true;
171 end 181 end
172 182
173 if usermanager_user_exists(username, host) then 183 if usermanager_user_exists(username, host) then
174 log("debug", "Attempt to register with existing username"); 184 log("debug", "Attempt to register with existing username");
175 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); 185 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists."));
176 return true; 186 return true;
177 end 187 end
178 188
179 -- TODO unable to write file, file may be locked, etc, what's the correct error? 189 local created, err = usermanager_create_user(username, password, host);
180 local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."); 190 if created then
181 if usermanager_create_user(username, password, host) then
182 data.registered = os.time(); 191 data.registered = os.time();
183 if not account_details:set(username, data) then 192 if not account_details:set(username, data) then
184 log("debug", "Could not store extra details"); 193 log("debug", "Could not store extra details");
185 usermanager_delete_user(username, host); 194 usermanager_delete_user(username, host);
186 session.send(error_reply); 195 session.send(st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."));
187 return true; 196 return true;
188 end 197 end
189 session.send(st.reply(stanza)); -- user created! 198 session.send(st.reply(stanza)); -- user created!
190 log("info", "User account created: %s@%s", username, host); 199 log("info", "User account created: %s@%s", username, host);
191 module:fire_event("user-registered", { 200 module:fire_event("user-registered", {
192 username = username, host = host, source = "mod_register", 201 username = username, host = host, source = "mod_register",
193 session = session }); 202 session = session });
194 else 203 else
195 log("debug", "Could not create user"); 204 log("debug", "Could not create user", err);
196 session.send(error_reply); 205 session.send(st.error_reply(stanza, "cancel", "feature-not-implemented", err));
197 end 206 end
198 return true; 207 return true;
199 end); 208 end);