Mercurial > prosody-modules
changeset 721:9080b0898b6f
mod_register_json: modify logic to prevent an unnecessary call to usermanager.
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Mon, 25 Jun 2012 21:36:40 +0000 |
parents | 97f6d7c4aaed |
children | 5c7175be532b |
files | mod_register_json/mod_register_json.lua |
diffstat | 1 files changed, 8 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_register_json/mod_register_json.lua Sat Jun 23 00:44:32 2012 +0500 +++ b/mod_register_json/mod_register_json.lua Mon Jun 25 21:36:40 2012 +0000 @@ -96,11 +96,11 @@ -- We first check if the supplied username for registration is already there. -- And nodeprep the username local username = nodeprep(req_body["username"]) - if not usermanager.user_exists(username, req_body["host"]) then - if not username then - module:log("debug", "%s supplied an username containing invalid characters: %s", user, username) - return http_response(event, 406, "Supplied username contains invalid characters, see RFC 6122.") - else + if not username then + module:log("debug", "%s supplied an username containing invalid characters: %s", user, username) + return http_response(event, 406, "Supplied username contains invalid characters, see RFC 6122.") + else + if not usermanager.user_exists(username, req_body["host"]) then 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"] } }) @@ -110,10 +110,10 @@ module:log("error", "user creation failed: "..error) return http_response(event, 500, "Encountered server error while creating the user: "..error) end + else + module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username) + return http_response(event, 409, "User already exists.") end - else - module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username) - return http_response(event, 409, "User already exists.") end end end