Software /
code /
prosody-modules
Changeset
553:7310ceb7564f
mod_register_json: checking out if the user creation succeeded or not is good practice.
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Sat, 14 Jan 2012 22:17:58 +0000 |
parents | 552:d1e83cb12885 |
children | 554:a2b0174b5c48 |
files | mod_register_json/mod_register_json.lua |
diffstat | 1 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_register_json/mod_register_json.lua Sun Jan 15 02:56:51 2012 +0500 +++ b/mod_register_json/mod_register_json.lua Sat Jan 14 22:17:58 2012 +0000 @@ -96,10 +96,15 @@ module:log("debug", "%s supplied an username containing invalid characters: %s", user, username) return http_response(406, "Supplied username contains invalid characters, see RFC 6122.") else - usermanager.create_user(username, req_body["password"], req_body["host"]) - hosts[req_body["host"]].events.fire_event("user-registered", { username = username, host = req_body["host"], source = "mod_register_json", session = { ip = req_body["ip"] } }) - module:log("debug", "%s registration data submission for %s@%s is successful", user, username, req_body["host"]) - return http_response(200, "Done.") + local ok, error = usermanager.create_user(username, req_body["password"], req_body["host"]) + if ok then + hosts[req_body["host"]].events.fire_event("user-registered", { username = username, host = req_body["host"], source = "mod_register_json", session = { ip = req_body["ip"] } }) + module:log("debug", "%s registration data submission for %s@%s is successful", user, username, req_body["host"]) + return http_response(200, "Done.") + else + module:log("error", "user creation failed: "..error) + return http_response(500, "Encountered server error while creating the user: "..error) + end end else module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username)