Comparison

plugins/mod_register_ibr.lua @ 10290:b2ce3300f26a

mod_register_ibr: Distinguish between failure to create account or save extra data
author Kim Alvefur <zash@zash.se>
date Sun, 29 Sep 2019 17:34:47 +0200
parent 10287:a1c0395a59ae
child 10363:1010a1ff8d21
comparison
equal deleted inserted replaced
10289:8c59b20f71dc 10290:b2ce3300f26a
177 log("debug", "Attempt to register with existing username"); 177 log("debug", "Attempt to register with existing username");
178 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); 178 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists."));
179 return true; 179 return true;
180 end 180 end
181 181
182 -- TODO unable to write file, file may be locked, etc, what's the correct error? 182 local created, err = usermanager_create_user(username, password, host);
183 local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."); 183 if created then
184 if usermanager_create_user(username, password, host) then
185 data.registered = os.time(); 184 data.registered = os.time();
186 if not account_details:set(username, data) then 185 if not account_details:set(username, data) then
187 log("debug", "Could not store extra details"); 186 log("debug", "Could not store extra details");
188 usermanager_delete_user(username, host); 187 usermanager_delete_user(username, host);
189 session.send(error_reply); 188 session.send(st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."));
190 return true; 189 return true;
191 end 190 end
192 session.send(st.reply(stanza)); -- user created! 191 session.send(st.reply(stanza)); -- user created!
193 log("info", "User account created: %s@%s", username, host); 192 log("info", "User account created: %s@%s", username, host);
194 module:fire_event("user-registered", { 193 module:fire_event("user-registered", {
195 username = username, host = host, source = "mod_register", 194 username = username, host = host, source = "mod_register",
196 session = session }); 195 session = session });
197 else 196 else
198 log("debug", "Could not create user"); 197 log("debug", "Could not create user", err);
199 session.send(error_reply); 198 session.send(st.error_reply(stanza, "cancel", "feature-not-implemented", err));
200 end 199 end
201 return true; 200 return true;
202 end); 201 end);