Changeset

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
parents 362:bd0a8c032163
children 364:1edd3f7c749c
files mod_register_json/mod_register_json.lua
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_register_json/mod_register_json.lua	Tue Apr 12 20:50:43 2011 +0000
+++ b/mod_register_json/mod_register_json.lua	Tue Apr 12 22:40:26 2011 +0000
@@ -61,6 +61,12 @@
 		module:log("debug", "JSON data submitted for user registration by %s failed to Decode.", user); 
 		return http_response(400, "JSON Decoding failed.");
 	else
+		-- Decode JSON data and check that all bits are there else throw an error
+		req_body = json_decode(body);
+		if req_body["username"] == nil or req_body["password"] == nil or req_body["host"] == nil or req_body["ip"] == nil then
+			module:log("debug", "%s supplied an insufficent number of elements or wrong elements for the JSON registration", user); 
+			return http_response(400, "Invalid syntax.");
+		end
 		-- Check if user is an admin of said host
 		if not usermanager.is_admin(user, req_body["host"]) then
 			module:log("warn", "%s tried to submit registration data for %s but he's not an admin", user, req_body["host"]);