Changeset

991:929dcf3c4bcb

mod_register_json: small code cleanup & optimization.
author Marco Cirillo <maranda@lightwitch.org>
date Mon, 29 Apr 2013 23:39:21 +0200
parents 990:17ba2c59d661
children 992:794817421fc6
files mod_register_json/register_json/mod_register_json.lua
diffstat 1 files changed, 3 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mod_register_json/register_json/mod_register_json.lua	Mon Apr 29 23:32:16 2013 +0200
+++ b/mod_register_json/register_json/mod_register_json.lua	Mon Apr 29 23:39:21 2013 +0200
@@ -87,9 +87,7 @@
 end
 
 local function handle_req(event)
-	local response = event.response
 	local request = event.request
-	local body = request.body
 	if secure and not request.secure then return nil end
 
 	if request.method ~= "POST" then
@@ -98,7 +96,7 @@
 	
 	local req_body
 	-- We check that what we have is valid JSON wise else we throw an error...
-	if not pcall(function() req_body = json_decode(b64_decode(body)) end) then
+	if not pcall(function() req_body = json_decode(b64_decode(request.body)) end) then
 		module:log("debug", "Data submitted for user registration by %s failed to Decode.", user)
 		return http_response(event, 400, "Decoding failed.")
 	else
@@ -189,8 +187,6 @@
 end
 
 local function r_template(event, type)
-	local response = event.response
-
 	local data = open_file(files_base..type.."_t.html")
 	if data then
 		data = data:gsub("%%REG%-URL", base_path.."verify/")
@@ -199,7 +195,6 @@
 end
 
 local function handle_verify(event, path)
-	local response = event.response
 	local request = event.request
 	local body = request.body
 	if secure and not request.secure then return nil end
@@ -222,8 +217,8 @@
 		end
 	elseif request.method == "POST" then
 		if path == "" then
-			if not request.body then return http_response(event, 400, "Bad Request.") end
-			local uuid = urldecode(request.body):match("^uuid=(.*)$")
+			if not body then return http_response(event, 400, "Bad Request.") end
+			local uuid = urldecode(body):match("^uuid=(.*)$")
 
 			if not pending[uuid] then
 				return r_template(event, "fail")