Comparison

mod_register_json/mod_register_json.lua @ 927:a9dfa7232d88

Merge
author Matthew Wild <mwild1@gmail.com>
date Tue, 12 Mar 2013 12:10:25 +0000
parent 919:7d72fb45b1e4
comparison
equal deleted inserted replaced
926:f88381a39c56 927:a9dfa7232d88
67 if not pcall(function() req_body = json_decode(body) end) then 67 if not pcall(function() req_body = json_decode(body) end) then
68 module:log("debug", "JSON data submitted for user registration by %s failed to Decode.", user) 68 module:log("debug", "JSON data submitted for user registration by %s failed to Decode.", user)
69 return http_response(event, 400, "JSON Decoding failed.") 69 return http_response(event, 400, "JSON Decoding failed.")
70 else 70 else
71 -- Decode JSON data and check that all bits are there else throw an error 71 -- Decode JSON data and check that all bits are there else throw an error
72 req_body = json_decode(body)
73 if req_body["username"] == nil or req_body["password"] == nil or req_body["host"] == nil or req_body["ip"] == nil then 72 if req_body["username"] == nil or req_body["password"] == nil or req_body["host"] == nil or req_body["ip"] == nil then
74 module:log("debug", "%s supplied an insufficent number of elements or wrong elements for the JSON registration", user) 73 module:log("debug", "%s supplied an insufficent number of elements or wrong elements for the JSON registration", user)
75 return http_response(event, 400, "Invalid syntax.") 74 return http_response(event, 400, "Invalid syntax.")
76 end 75 end
77 -- Check if user is an admin of said host 76 -- Check if user is an admin of said host
84 83
85 -- We first check if the supplied username for registration is already there. 84 -- We first check if the supplied username for registration is already there.
86 -- And nodeprep the username 85 -- And nodeprep the username
87 local username = nodeprep(req_body["username"]) 86 local username = nodeprep(req_body["username"])
88 if not username then 87 if not username then
89 module:log("debug", "%s supplied an username containing invalid characters: %s", user, username) 88 module:log("debug", "An username containing invalid characters was supplied: %s", user)
90 return http_response(event, 406, "Supplied username contains invalid characters, see RFC 6122.") 89 return http_response(event, 406, "Supplied username contains invalid characters, see RFC 6122.")
91 else 90 else
92 if not usermanager.user_exists(username, req_body["host"]) then 91 if not usermanager.user_exists(username, req_body["host"]) then
93 -- if username fails to register successive requests shouldn't be throttled until one is successful. 92 -- if username fails to register successive requests shouldn't be throttled until one is successful.
94 if throttle_time and not whitelist:contains(req_body["ip"]) then 93 if throttle_time and not whitelist:contains(req_body["ip"]) then