Mercurial > prosody-modules
comparison mod_register_json/mod_register_json.lua @ 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 | 859bf77b9fbf |
| children | b62f5e38f865 |
comparison
equal
deleted
inserted
replaced
| 552:d1e83cb12885 | 553:7310ceb7564f |
|---|---|
| 94 if not usermanager.user_exists(username, req_body["host"]) then | 94 if not usermanager.user_exists(username, req_body["host"]) then |
| 95 if not username then | 95 if not username then |
| 96 module:log("debug", "%s supplied an username containing invalid characters: %s", user, username) | 96 module:log("debug", "%s supplied an username containing invalid characters: %s", user, username) |
| 97 return http_response(406, "Supplied username contains invalid characters, see RFC 6122.") | 97 return http_response(406, "Supplied username contains invalid characters, see RFC 6122.") |
| 98 else | 98 else |
| 99 usermanager.create_user(username, req_body["password"], req_body["host"]) | 99 local ok, error = usermanager.create_user(username, req_body["password"], req_body["host"]) |
| 100 hosts[req_body["host"]].events.fire_event("user-registered", { username = username, host = req_body["host"], source = "mod_register_json", session = { ip = req_body["ip"] } }) | 100 if ok then |
| 101 module:log("debug", "%s registration data submission for %s@%s is successful", user, username, req_body["host"]) | 101 hosts[req_body["host"]].events.fire_event("user-registered", { username = username, host = req_body["host"], source = "mod_register_json", session = { ip = req_body["ip"] } }) |
| 102 return http_response(200, "Done.") | 102 module:log("debug", "%s registration data submission for %s@%s is successful", user, username, req_body["host"]) |
| 103 return http_response(200, "Done.") | |
| 104 else | |
| 105 module:log("error", "user creation failed: "..error) | |
| 106 return http_response(500, "Encountered server error while creating the user: "..error) | |
| 107 end | |
| 103 end | 108 end |
| 104 else | 109 else |
| 105 module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username) | 110 module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username) |
| 106 return http_response(409, "User already exists.") | 111 return http_response(409, "User already exists.") |
| 107 end | 112 end |
