Comparison

mod_register_json/mod_register_json.lua @ 363:72a5778579c5

mod_register_json: Let's call it the first commit, fixed all code errors (aka it works).
author Marco Cirillo <maranda@lightwitch.org>
date Tue, 12 Apr 2011 22:40:26 +0000
parent 362:bd0a8c032163
child 364:1edd3f7c749c
comparison
equal deleted inserted replaced
362:bd0a8c032163 363:72a5778579c5
59 -- We check that what we have is valid JSON wise else we throw an error... 59 -- We check that what we have is valid JSON wise else we throw an error...
60 if not pcall(function() req_body = json_decode(body) end) then 60 if not pcall(function() req_body = json_decode(body) end) then
61 module:log("debug", "JSON data submitted for user registration by %s failed to Decode.", user); 61 module:log("debug", "JSON data submitted for user registration by %s failed to Decode.", user);
62 return http_response(400, "JSON Decoding failed."); 62 return http_response(400, "JSON Decoding failed.");
63 else 63 else
64 -- Decode JSON data and check that all bits are there else throw an error
65 req_body = json_decode(body);
66 if req_body["username"] == nil or req_body["password"] == nil or req_body["host"] == nil or req_body["ip"] == nil then
67 module:log("debug", "%s supplied an insufficent number of elements or wrong elements for the JSON registration", user);
68 return http_response(400, "Invalid syntax.");
69 end
64 -- Check if user is an admin of said host 70 -- Check if user is an admin of said host
65 if not usermanager.is_admin(user, req_body["host"]) then 71 if not usermanager.is_admin(user, req_body["host"]) then
66 module:log("warn", "%s tried to submit registration data for %s but he's not an admin", user, req_body["host"]); 72 module:log("warn", "%s tried to submit registration data for %s but he's not an admin", user, req_body["host"]);
67 return http_response(401, "I obey only to my masters... Have a nice day."); 73 return http_response(401, "I obey only to my masters... Have a nice day.");
68 else 74 else