mod_register_json/mod_register_json.lua
author Marco Cirillo <maranda@lightwitch.org>
Sun, 29 Apr 2012 20:16:43 +0000
changeset 655 81d269f97ea2
parent 651 78a23a7dc613
child 660 aa3fbb33700d
permissions -rw-r--r--
mod_register_json: revert change, it's not needed (providing http provides https as well)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
     1
-- Expose a simple servlet to handle user registrations from web pages
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
     2
-- via JSON.
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
     3
--
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
     4
-- A Good chunk of the code is from mod_data_access.lua by Kim Alvefur
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
     5
-- aka Zash.
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
     6
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
     7
local jid_prep = require "util.jid".prep
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
     8
local jid_split = require "util.jid".split
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
     9
local usermanager = require "core.usermanager"
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    10
local b64_decode = require "util.encodings".base64.decode
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    11
local json_decode = require "util.json".decode
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    12
local os_time = os.time
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    13
local nodeprep = require "util.encodings".stringprep.nodeprep
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    14
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    15
module:depends("http")
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    16
module:set_global()
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    17
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    18
-- Pick up configuration.
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    19
651
78a23a7dc613 mod_register_json: fixed typo, added https/http switch and default value to it.
Marco Cirillo <maranda@lightwitch.org>
parents: 648
diff changeset
    20
local secure = module:get_option_boolean("reg_servlet_secure", true)
560
b62f5e38f865 mod_register_json: added auto-cleanup logic to the module so it can at least be unloaded and reloaded without fuss. (Experimental: works with server_select and trunk)
Marco Cirillo <maranda@lightwitch.org>
parents: 553
diff changeset
    21
local set_realm_name = module:get_option_string("reg_servlet_realm", "Restricted")
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    22
local base_path = module:get_option_string("reg_servlet_base", "/register_account/")
560
b62f5e38f865 mod_register_json: added auto-cleanup logic to the module so it can at least be unloaded and reloaded without fuss. (Experimental: works with server_select and trunk)
Marco Cirillo <maranda@lightwitch.org>
parents: 553
diff changeset
    23
local throttle_time = module:get_option_number("reg_servlet_ttime", nil)
550
d8143f627f9f mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
Marco Cirillo <maranda@lightwitch.org>
parents: 548
diff changeset
    24
local whitelist = module:get_option_set("reg_servlet_wl", {})
d8143f627f9f mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
Marco Cirillo <maranda@lightwitch.org>
parents: 548
diff changeset
    25
local blacklist = module:get_option_set("reg_servlet_bl", {})
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    26
local recent_ips = {}
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    27
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    28
-- Begin
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    29
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    30
local function http_response(event, code, message, headers)
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    31
	local response = event.response
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    32
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    33
	if headers then
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    34
		for header, data in pairs(headers) do response.headers[header] = data end
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    35
	end
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    36
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    37
	response.headers.content_type = "application/json"
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    38
	response.status_code = code
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    39
	response:send(message)
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    40
end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    41
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    42
local function handle_req(event)
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    43
	local request = event.request
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    44
	local body = request.body
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    45
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    46
	if request.method ~= "POST" then
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    47
		return http_response(event, 405, "Bad method...", {["Allow"] = "POST"})
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    48
	end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    49
	if not request.headers["authorization"] then
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    50
		return http_response(event, 401, "No... No...", {["WWW-Authenticate"]='Basic realm="'.. set_realm_name ..'"'})
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    51
	end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    52
	
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    53
	local user, password = b64_decode(request.headers.authorization:match("[^ ]*$") or ""):match("([^:]*):(.*)")
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    54
	user = jid_prep(user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    55
	if not user or not password then return http_response(event, 400, "What's this..?") end
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    56
	local user_node, user_host = jid_split(user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    57
	if not hosts[user_host] then return http_response(event, 401, "Negative.") end
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    58
	
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    59
	module:log("warn", "%s is authing to submit a new user registration data", user)
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    60
	if not usermanager.test_password(user_node, user_host, password) then
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    61
		module:log("warn", "%s failed authentication", user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    62
		return http_response(event, 401, "Who the hell are you?! Guards!")
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    63
	end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    64
	
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    65
	local req_body
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    66
	-- We check that what we have is valid JSON wise else we throw an error...
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    67
	if not pcall(function() req_body = json_decode(body) end) then
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    68
		module:log("debug", "JSON data submitted for user registration by %s failed to Decode.", user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    69
		return http_response(event, 400, "JSON Decoding failed.")
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
    70
	else
363
72a5778579c5 mod_register_json: Let's call it the first commit, fixed all code errors (aka it works).
Marco Cirillo <maranda@lightwitch.org>
parents: 362
diff changeset
    71
		-- Decode JSON data and check that all bits are there else throw an error
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    72
		req_body = json_decode(body)
363
72a5778579c5 mod_register_json: Let's call it the first commit, fixed all code errors (aka it works).
Marco Cirillo <maranda@lightwitch.org>
parents: 362
diff changeset
    73
		if req_body["username"] == nil or req_body["password"] == nil or req_body["host"] == nil or req_body["ip"] == nil then
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    74
			module:log("debug", "%s supplied an insufficent number of elements or wrong elements for the JSON registration", user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    75
			return http_response(event, 400, "Invalid syntax.")
363
72a5778579c5 mod_register_json: Let's call it the first commit, fixed all code errors (aka it works).
Marco Cirillo <maranda@lightwitch.org>
parents: 362
diff changeset
    76
		end
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    77
		-- Check if user is an admin of said host
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    78
		if not usermanager.is_admin(user, req_body["host"]) then
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    79
			module:log("warn", "%s tried to submit registration data for %s but he's not an admin", user, req_body["host"])
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
    80
			return http_response(event, 401, "I obey only to my masters... Have a nice day.")
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    81
		else	
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    82
			-- Checks for both Throttling/Whitelist and Blacklist (basically copycatted from prosody's register.lua code)
550
d8143f627f9f mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
Marco Cirillo <maranda@lightwitch.org>
parents: 548
diff changeset
    83
			if blacklist:contains(req_body["ip"]) then module:log("warn", "Attempt of reg. submission to the JSON servlet from blacklisted address: %s", req_body["ip"]) ; return http_response(403, "The specified address is blacklisted, sorry sorry.") end
d8143f627f9f mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
Marco Cirillo <maranda@lightwitch.org>
parents: 548
diff changeset
    84
			if throttle_time and not whitelist:contains(req_body["ip"]) then
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    85
				if not recent_ips[req_body["ip"]] then
586
1004d7176be2 mod_register_json: cleanup unused stuff
Marco Cirillo <maranda@lightwitch.org>
parents: 566
diff changeset
    86
					recent_ips[req_body["ip"]] = os_time()
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    87
				else
586
1004d7176be2 mod_register_json: cleanup unused stuff
Marco Cirillo <maranda@lightwitch.org>
parents: 566
diff changeset
    88
					if os_time() - recent_ips[req_body["ip"]] < throttle_time then
1004d7176be2 mod_register_json: cleanup unused stuff
Marco Cirillo <maranda@lightwitch.org>
parents: 566
diff changeset
    89
						recent_ips[req_body["ip"]] = os_time()
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    90
						module:log("warn", "JSON Registration request from %s has been throttled.", req_body["ip"])
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    91
						return http_response(503, "Woah... How many users you want to register..? Request throttled, wait a bit and try again.")
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    92
					end
586
1004d7176be2 mod_register_json: cleanup unused stuff
Marco Cirillo <maranda@lightwitch.org>
parents: 566
diff changeset
    93
					recent_ips[req_body["ip"]] = os_time()
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    94
				end
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
    95
			end
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    96
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
    97
			-- We first check if the supplied username for registration is already there.
430
f0fafd19fd72 mod_register_json: changed pestered code to something less pestered. (added nodeprep)
Marco Cirillo <maranda@lightwitch.org>
parents: 429
diff changeset
    98
			-- And nodeprep the username
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
    99
			local username = nodeprep(req_body["username"])
430
f0fafd19fd72 mod_register_json: changed pestered code to something less pestered. (added nodeprep)
Marco Cirillo <maranda@lightwitch.org>
parents: 429
diff changeset
   100
			if not usermanager.user_exists(username, req_body["host"]) then
f0fafd19fd72 mod_register_json: changed pestered code to something less pestered. (added nodeprep)
Marco Cirillo <maranda@lightwitch.org>
parents: 429
diff changeset
   101
				if not username then
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
   102
					module:log("debug", "%s supplied an username containing invalid characters: %s", user, username)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   103
					return http_response(event, 406, "Supplied username contains invalid characters, see RFC 6122.")
429
ea6641deec12 mod_register_json: added check for invalid characters in the username.
Marco Cirillo <maranda@lightwitch.org>
parents: 370
diff changeset
   104
				else
553
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
   105
					local ok, error = usermanager.create_user(username, req_body["password"], req_body["host"])
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
   106
					if ok then 
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
   107
						hosts[req_body["host"]].events.fire_event("user-registered", { username = username, host = req_body["host"], source = "mod_register_json", session = { ip = req_body["ip"] } })
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
   108
						module:log("debug", "%s registration data submission for %s@%s is successful", user, username, req_body["host"])
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   109
						return http_response(event, 200, "Done.")
553
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
   110
					else
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
   111
						module:log("error", "user creation failed: "..error)
651
78a23a7dc613 mod_register_json: fixed typo, added https/http switch and default value to it.
Marco Cirillo <maranda@lightwitch.org>
parents: 648
diff changeset
   112
						return http_response(event, 500, "Encountered server error while creating the user: "..error)
553
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
   113
					end
429
ea6641deec12 mod_register_json: added check for invalid characters in the username.
Marco Cirillo <maranda@lightwitch.org>
parents: 370
diff changeset
   114
				end
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
   115
			else
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
   116
				module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   117
				return http_response(event, 409, "User already exists.")
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
   118
			end
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
   119
		end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
   120
	end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
   121
end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
   122
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
   123
-- Set it up!
560
b62f5e38f865 mod_register_json: added auto-cleanup logic to the module so it can at least be unloaded and reloaded without fuss. (Experimental: works with server_select and trunk)
Marco Cirillo <maranda@lightwitch.org>
parents: 553
diff changeset
   124
655
81d269f97ea2 mod_register_json: revert change, it's not needed (providing http provides https as well)
Marco Cirillo <maranda@lightwitch.org>
parents: 651
diff changeset
   125
module:provides("http", {
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   126
	default_path = base_path,
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   127
        route = {
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   128
                ["GET /"] = handle_req,
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   129
		["POST /"] = handle_req
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   130
        }
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
   131
})