comparison mod_register_json/mod_register_json.lua @ 651:78a23a7dc613

mod_register_json: fixed typo, added https/http switch and default value to it.
author Marco Cirillo <maranda@lightwitch.org>
date Sun, 29 Apr 2012 13:44:21 +0000
parents 6f0e0d6790a7
children 81d269f97ea2
comparison
equal deleted inserted replaced
650:34e7093cf419 651:78a23a7dc613
15 module:depends("http") 15 module:depends("http")
16 module:set_global() 16 module:set_global()
17 17
18 -- Pick up configuration. 18 -- Pick up configuration.
19 19
20 local secure = module:get_option_boolean("reg_servlet_secure", true)
20 local set_realm_name = module:get_option_string("reg_servlet_realm", "Restricted") 21 local set_realm_name = module:get_option_string("reg_servlet_realm", "Restricted")
21 local base_path = module:get_option_string("reg_servlet_base", "/register_account/") 22 local base_path = module:get_option_string("reg_servlet_base", "/register_account/")
22 local throttle_time = module:get_option_number("reg_servlet_ttime", nil) 23 local throttle_time = module:get_option_number("reg_servlet_ttime", nil)
23 local whitelist = module:get_option_set("reg_servlet_wl", {}) 24 local whitelist = module:get_option_set("reg_servlet_wl", {})
24 local blacklist = module:get_option_set("reg_servlet_bl", {}) 25 local blacklist = module:get_option_set("reg_servlet_bl", {})
106 hosts[req_body["host"]].events.fire_event("user-registered", { username = username, host = req_body["host"], source = "mod_register_json", session = { ip = req_body["ip"] } }) 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"] } })
107 module:log("debug", "%s registration data submission for %s@%s is successful", user, username, req_body["host"]) 108 module:log("debug", "%s registration data submission for %s@%s is successful", user, username, req_body["host"])
108 return http_response(event, 200, "Done.") 109 return http_response(event, 200, "Done.")
109 else 110 else
110 module:log("error", "user creation failed: "..error) 111 module:log("error", "user creation failed: "..error)
111 return http_response(event 500, "Encountered server error while creating the user: "..error) 112 return http_response(event, 500, "Encountered server error while creating the user: "..error)
112 end 113 end
113 end 114 end
114 else 115 else
115 module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username) 116 module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username)
116 return http_response(event, 409, "User already exists.") 117 return http_response(event, 409, "User already exists.")
119 end 120 end
120 end 121 end
121 122
122 -- Set it up! 123 -- Set it up!
123 124
124 module:provides("http", { 125 module:provides((secure and "https" or "http"), {
125 default_path = base_path, 126 default_path = base_path,
126 route = { 127 route = {
127 ["GET /"] = handle_req, 128 ["GET /"] = handle_req,
128 ["POST /"] = handle_req 129 ["POST /"] = handle_req
129 } 130 }