Mercurial > prosody-modules
annotate mod_invites_register_web/mod_invites_register_web.lua @ 6299:5cf5ee23b361
mod_voipms: New Module to send and receive SMS/MMS via VoIP.ms APIs.
diff --git a/mod_voipms/README.md b/mod_voipms/README.md
new file mode 100644
--- /dev/null
+++ b/mod_voipms/README.md
@@ -0,0 +1,51 @@
+---
+labels:
+- 'Stage-Alpha'
+- 'Type-Web'
+summary: Send and receive SMS/MMS via VoIP.ms APIs.
+rockspec:
+ build:
+ modules:
+ mod_voipms: mod_voipms.lua
+...
+
+Introduction
+============
+
+This is a Prosody module to map JIDs to DIDs on VoIP.ms and support sending/receiving SMS/MMS.
+
+Configuration
+=============
+
+| option | type | default |
+|-----------------------|--------|---------|
+| voipms\_api\_username | string | nil |
+| voipms\_api\_password | string | nil |
+| voipms\_query\_key | string | nil |
+| voipms\_jid\_map | table | nil |
+```
+VirtualHost "sms.example.com"
+modules_enabled = {
+ "voipms";
+}
+voipms_api_username = john@example.com -- E-mail registered with VoIP.ms
+voipms_api_password = abcd1234 -- API password configured in VoIP.ms
+voipms_query_key = some_query_key -- query param 'key' part of your URL callback
+voipms_jid_map = {
+ ["your_jid@your_domain.com"] = "+1234567890"
+}
+```
+
+HTTP
+====
+
+The module is served on Prosody's default HTTP ports at the path /voipms. More details on configuring HTTP modules in Prosody can be found in the HTTP documentation.
+
+VoIP.ms Webhook URL
+===================
+
+This module receives the VoIP.ms Webhook URL (POST) at the /voipms endpoint. It uses the sendSMS/sendMMS GET methods against the VoIP.ms APIs. This is an example webhook to use in VoIP.ms:
+
+```
+https://sms.example.com/voipms?key=some_query_key
+```
diff --git a/mod_voipms/mod_voipms.lua b/mod_voipms/mod_voipms.lua
new file mode 100644
--- /dev/null
+++ b/mod_voipms/mod_voipms.lua
@@ -0,0 +1,166 @@
+local http = require "net.http"
+local json = require "util.json"
+local st = require "util.stanza"
+
+local api_username = module:get_option_string("voipms_api_username")
+local api_password = module:get_option_string("voipms_api_password")
+local query_key = module:get_option("voipms_query_key")
+local jid_map = module:get_option("voipms_jid_map") or {}
+local rest_endpoint = "https://voip.ms/api/v1/rest.php"
+
+if not api_username or not api_password or not query_key then
+ module:log("error", "Missing required config values (voipms_api_username, voipms_api_password, voipms_query_key)")
+ return
+end
+
+module:depends("http")
+
+local function normalize_number(num)
+ if not num then return nil end
+ if num:sub(1, 1) ~= "+" then
+ return "+1" .. num
+ end
+ return num
+end
+
+local function extract_query_key(event)
+ return (event.request.url.query or ""):match("key=([^&]+)")
+end
+
+module:provides("http", {
+ route = {
+ ["POST"] = function(event)
+ local req = event.request
+ local body = req.body or ""
+
+ if extract_query_key(event) ~= query_key then
+ module:log("warn", "Unauthorized webhook: missing or invalid key")
+ return { status_code = 403 }
+ end
+
+ local json_payload, err = json.decode(body)
+ if not json_payload then
+ module:log("warn", "Invalid JSON: %s", err or "unknown error")
+ return { status_code = 400 }
+ end
+
+ local payload = json_payload.data and json_payload.data.payload
+ if not payload then
+ module:log("warn", "Missing payload in JSON")
+ return { status_code = 400 }
+ end
+
+ local from = payload.from and payload.from.phone_number
+ local to_list = payload.to or {}
+ local to = #to_list > 0 and to_list[1].phone_number or nil
+
+ if not from or not to then
+ module:log("warn", "Missing phone numbers (from: %s, to: %s)", tostring(from), tostring(to))
+ return { status_code = 400 }
+ end
+
+ local normalized_to = normalize_number(to)
+ local target_jid = nil
+
+ for jid, did in pairs(jid_map) do
+ if normalize_number(did) == normalized_to then
+ target_jid = jid
+ break
+ end
+ end
+
+ if not target_jid then
+ module:log("warn", "No JID mapping for DID %s", normalized_to)
+ return { status_code = 404 }
+ end
+
+ local normalized_from = normalize_number(from)
+ local message_text = payload.text or ""
+
+ local message = st.message({
+ from = normalized_from .. "@" .. module.host,
+ to = target_jid,
+ type = "chat"
+ }):tag("body"):text(message_text):up()
+
+ if payload.media and #payload.media > 0 then
+ for _, media_item in ipairs(payload.media) do
+ if media_item.url then
+ message_text = message_text .. "\n" .. media_item.url
+ message:tag("x", { xmlns = "jabber:x:oob" })
+ :tag("url"):text(media_item.url):up():up()
+ end
+ end
+ end
+
+ module:send(message)
+ module:log("info", "Delivered SMS from %s to %s", normalized_from, target_jid)
+
+ return { status_code = 204 }
+ end
+ }
+})
+
+module:hook("message/bare", function(event)
+ local stanza = event.stanza
+ if stanza.attr.type ~= "chat" then return end
+
+ local from_jid = stanza.attr.from
+ local to_jid = stanza.attr.to
+ local body = stanza:get_child_text("body")
+ if not body or body == "" then return end
+
+ local from_number = jid_map[from_jid]
+ if not from_number then
+ module:log("warn", "No DID mapping for JID %s", from_jid)
+ return
+ end
+
+ local to_number = to_jid:match("^([^@]+)")
+ if not to_number then
+ module:log("warn", "Malformed JID in message.to: %s", to_jid)
+ return
+ end
+
+ to_number = normalize_number(to_number)
+
+ local media_urls = {}
+ for line in body:gmatch("[^\r\n]+") do
+ if line:match("^https?://") then
+ table.insert(media_urls, line)
+ end
+ end
+
+ local method = (#media_urls > 0) and "sendMMS" or "sendSMS"
+ local query = {
+ api_username = api_username,
+ api_password = api_password,
+ method = method,
+ did = from_number,
+ dst = to_number,
+ message = body
+ }
+
+ if method == "sendMMS" then
+ for i, url in ipairs(media_urls) do
+ query["media_url[" .. (i - 1) .. "]"] = url
+ end
+ end
+
+ local query_str = http.formencode(query)
+
+ http.request(rest_endpoint .. "?" .. query_str, {
+ method = "GET";
+ }, function(response_body, code)
+ if code == 200 then
+ local resp, err = json.decode(response_body)
+ if not resp or resp.status ~= "success" then
+ module:log("error", "Failed to send %s: %s", method, err or (resp and resp.status) or "unknown")
+ else
+ module:log("info", "Sent %s from %s to %s", method, from_number, to_number)
+ end
+ else
+ module:log("error", "HTTP error sending %s: code %s", method, tostring(code))
+ end
+ end)
+end)
| author | Chaz <menel@snikket.de> |
|---|---|
| date | Mon, 21 Jul 2025 23:57:37 +0200 |
| parents | 29a646bad096 |
| children | 6216d85162dc |
| rev | line source |
|---|---|
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local id = require "util.id"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local http_formdecode = require "net.http".formdecode; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local usermanager = require "core.usermanager"; |
|
4167
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
4 local modulemanager = require "core.modulemanager"; |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local nodeprep = require "util.encodings".stringprep.nodeprep; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local st = require "util.stanza"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local url_escape = require "util.http".urlencode; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local render_html_template = require"util.interpolation".new("%b{}", st.xml_escape, { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 urlescape = url_escape; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 }); |
|
4175
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
11 local render_url = require "util.interpolation".new("%b{}", url_escape, { |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
12 urlescape = url_escape; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
13 noscheme = function (url) |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
14 return (url:gsub("^[^:]+:", "")); |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
15 end; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
16 }); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 module:depends("register_apps"); |
|
4833
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
19 local mod_password_policy = module:depends("password_policy"); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local site_name = module:get_option_string("site_name", module.host); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local site_apps = module:shared("register_apps/apps"); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
|
4167
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
24 local webchat_url = module:get_option_string("webchat_url"); |
|
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
25 |
|
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
26 -- If not provided, but mod_conversejs is loaded, default to that |
|
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
27 if not webchat_url and modulemanager.get_modules_for_host(module.host):contains("conversejs") then |
|
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
28 local conversejs = module:depends("conversejs"); |
|
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
29 webchat_url = conversejs.module:http_url(); |
|
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
30 end |
|
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
31 |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 module:depends("http"); |
|
4108
f49e3ea99785
mod_invites_register_web: Remove dependency on mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4093
diff
changeset
|
33 |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local invites = module:depends("invites"); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local invites_page = module:depends("invites_page"); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
|
6227
29a646bad096
mod_invites_register_web: Allow pointing other HTML templates
Kim Alvefur <zash@zash.se>
parents:
4833
diff
changeset
|
37 local template_path = module:get_option_path("invites_register_template_path", "html"); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 function serve_register_page(event) |
|
6227
29a646bad096
mod_invites_register_web: Allow pointing other HTML templates
Kim Alvefur <zash@zash.se>
parents:
4833
diff
changeset
|
39 local register_page_template = assert(module:load_resource(template_path .. "/register.html")):read("*a"); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
|
4112
d0366474aace
mod_invites_register_web: Fix traceback on missing query params
Matthew Wild <mwild1@gmail.com>
parents:
4108
diff
changeset
|
41 local query_params = event.request.url.query and http_formdecode(event.request.url.query); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 |
|
4112
d0366474aace
mod_invites_register_web: Fix traceback on missing query params
Matthew Wild <mwild1@gmail.com>
parents:
4108
diff
changeset
|
43 local invite = query_params and invites.get(query_params.t); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 if not invite then |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 status_code = 303; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 headers = { |
|
4174
e56b6b6852ae
mod_invites_register_web: Fix bug where invalid invite code redirected to wrong URL
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
48 ["Location"] = invites_page.module:http_url().."?"..(event.request.url.query or ""); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 }; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 }; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 |
|
4129
ca099bd28bf5
mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents:
4119
diff
changeset
|
53 event.response.headers["Content-Type"] = "text/html; charset=utf-8"; |
|
ca099bd28bf5
mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents:
4119
diff
changeset
|
54 |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 local invite_page = render_html_template(register_page_template, { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 site_name = site_name; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 token = invite.token; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 domain = module.host; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 uri = invite.uri; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 type = invite.type; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 jid = invite.jid; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 inviter = invite.inviter; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 app = query_params.c and site_apps[query_params.c]; |
|
4833
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
64 password_policy = mod_password_policy.get_policy(); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 }); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 return invite_page; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 function handle_register_form(event) |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 local request, response = event.request, event.response; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 local form_data = http_formdecode(request.body); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 local user, password, token = form_data["user"], form_data["password"], form_data["token"]; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 local app_id = form_data["app_id"]; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 |
|
6227
29a646bad096
mod_invites_register_web: Allow pointing other HTML templates
Kim Alvefur <zash@zash.se>
parents:
4833
diff
changeset
|
75 local register_page_template = assert(module:load_resource(template_path .. "/register.html")):read("*a"); |
|
29a646bad096
mod_invites_register_web: Allow pointing other HTML templates
Kim Alvefur <zash@zash.se>
parents:
4833
diff
changeset
|
76 local error_template = assert(module:load_resource(template_path .. "/register_error.html")):read("*a"); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 local invite = invites.get(token); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 if not invite then |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 return { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 status_code = 303; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 headers = { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 ["Location"] = invites_page.module:http_url().."?"..event.request.url.query; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 }; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 }; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 |
|
4129
ca099bd28bf5
mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents:
4119
diff
changeset
|
88 event.response.headers["Content-Type"] = "text/html; charset=utf-8"; |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 if not user or #user == 0 or not password or #password == 0 or not token then |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 return render_html_template(register_page_template, { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 site_name = site_name; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 token = invite.token; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 domain = module.host; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 uri = invite.uri; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 type = invite.type; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 jid = invite.jid; |
|
4833
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
98 password_policy = mod_password_policy.get_policy(); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 msg_class = "alert-warning"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 message = "Please fill in all fields."; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 }); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 -- Shamelessly copied from mod_register_web. |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 local prepped_username = nodeprep(user); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 if not prepped_username or #prepped_username == 0 then |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 return render_html_template(register_page_template, { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 site_name = site_name; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 token = invite.token; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 domain = module.host; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 uri = invite.uri; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 type = invite.type; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 jid = invite.jid; |
|
4833
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
116 password_policy = mod_password_policy.get_policy(); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 msg_class = "alert-warning"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 message = "This username contains invalid characters."; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 }); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 if usermanager.user_exists(prepped_username, module.host) then |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 return render_html_template(register_page_template, { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 site_name = site_name; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 token = invite.token; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 domain = module.host; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 uri = invite.uri; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 type = invite.type; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 jid = invite.jid; |
|
4833
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
131 password_policy = mod_password_policy.get_policy(); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 msg_class = "alert-warning"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 message = "This username is already in use."; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 }); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 |
|
4833
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
138 local pw_ok, pw_error = mod_password_policy.check_password(password, { |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
139 username = prepped_username; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
140 }); |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
141 if not pw_ok then |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
142 return render_html_template(register_page_template, { |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
143 site_name = site_name; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
144 token = invite.token; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
145 domain = module.host; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
146 uri = invite.uri; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
147 type = invite.type; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
148 jid = invite.jid; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
149 password_policy = mod_password_policy.get_policy(); |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
150 |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
151 msg_class = "alert-warning"; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
152 message = pw_error; |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
153 }); |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
154 end |
|
15cf32e666da
mod_invites_register_web: Add mod_password_policy checks for web registration
Matthew Wild <mwild1@gmail.com>
parents:
4175
diff
changeset
|
155 |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 local registering = { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 validated_invite = invite; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 username = prepped_username; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 host = module.host; |
|
4117
a1c6eea971ce
mod_invites_register_web: Include request.ip in user-registering event (thanks franck)
Matthew Wild <mwild1@gmail.com>
parents:
4112
diff
changeset
|
160 ip = request.ip; |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 allowed = true; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 }; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 module:fire_event("user-registering", registering); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 if not registering.allowed then |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 return render_html_template(error_template, { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 site_name = site_name; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 msg_class = "alert-danger"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 message = registering.reason or "Registration is not allowed."; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 }); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 local ok, err = usermanager.create_user(prepped_username, password, module.host); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 if ok then |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 module:fire_event("user-registered", { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 username = prepped_username; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 host = module.host; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 source = "mod_"..module.name; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 validated_invite = invite; |
|
4119
559ca8d93302
mod_invites_register_web: Also add ip to user-registered
Matthew Wild <mwild1@gmail.com>
parents:
4117
diff
changeset
|
182 ip = request.ip; |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 }); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 local app_info = site_apps[app_id]; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 local success_template; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 if app_info then |
|
4175
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
189 if app_info.login_link_format then |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
190 local redirect_url = render_url(app_info.login_link_format, { |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
191 site_name = site_name; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
192 username = prepped_username; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
193 domain = module.host; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
194 password = password; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
195 app = app_info; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
196 }); |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
197 return { |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
198 status_code = 303; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
199 headers = { |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
200 ["Location"] = redirect_url; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
201 }; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
202 }; |
|
39d1a4ecdee6
mod_invites_register_web: Support a 'login_link_format' for apps, redirected to after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4174
diff
changeset
|
203 end |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 -- If recognised app, we serve a page that includes setup instructions |
|
6227
29a646bad096
mod_invites_register_web: Allow pointing other HTML templates
Kim Alvefur <zash@zash.se>
parents:
4833
diff
changeset
|
205 success_template = assert(module:load_resource(template_path .. "/register_success_setup.html")):read("*a"); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 else |
|
6227
29a646bad096
mod_invites_register_web: Allow pointing other HTML templates
Kim Alvefur <zash@zash.se>
parents:
4833
diff
changeset
|
207 success_template = assert(module:load_resource(template_path .. "/register_success.html")):read("*a"); |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 -- Due to the credentials being served here, ensure that |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 -- the browser or any intermediary does not cache the page |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 event.response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 event.response.headers["Pragma"] = "no-cache"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 event.response.headers["Expires"] = "0"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 return render_html_template(success_template, { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 site_name = site_name; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 username = prepped_username; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 domain = module.host; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 password = password; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 app = app_info; |
|
4167
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
222 webchat_url = webchat_url; |
|
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 }); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 else |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 local err_id = id.short(); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 module:log("warn", "Registration failed (%s): %s", err_id, tostring(err)); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 return render_html_template(error_template, { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 site_name = site_name; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 msg_class = "alert-danger"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 message = ("An unknown error has occurred (%s)"):format(err_id); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 }); |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 end |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 module:provides("http", { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 default_path = "register"; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 route = { |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 ["GET"] = serve_register_page; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 ["POST"] = handle_register_form; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 }; |
|
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 }); |
