Mercurial > prosody-modules
annotate mod_invites_register_web/mod_invites_register_web.lua @ 4167:3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 05 Oct 2020 16:45:06 +0100 |
parents | ca099bd28bf5 |
children | e56b6b6852ae |
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 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 module:depends("register_apps"); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 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
|
16 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
|
17 |
4167
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
18 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
|
19 |
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
20 -- 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
|
21 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
|
22 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
|
23 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
|
24 end |
3a03ae9a0882
mod_invites_register_web: Support linking to a web chat after successful registration
Matthew Wild <mwild1@gmail.com>
parents:
4129
diff
changeset
|
25 |
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 module:depends("http"); |
4108
f49e3ea99785
mod_invites_register_web: Remove dependency on mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4093
diff
changeset
|
27 |
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 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
|
29 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
|
30 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 function serve_register_page(event) |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 local register_page_template = assert(module:load_resource("html/register.html")):read("*a"); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
4112
d0366474aace
mod_invites_register_web: Fix traceback on missing query params
Matthew Wild <mwild1@gmail.com>
parents:
4108
diff
changeset
|
34 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
|
35 |
4112
d0366474aace
mod_invites_register_web: Fix traceback on missing query params
Matthew Wild <mwild1@gmail.com>
parents:
4108
diff
changeset
|
36 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
|
37 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
|
38 return { |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 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
|
40 headers = { |
4112
d0366474aace
mod_invites_register_web: Fix traceback on missing query params
Matthew Wild <mwild1@gmail.com>
parents:
4108
diff
changeset
|
41 ["Location"] = invites.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
|
42 }; |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 }; |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
4129
ca099bd28bf5
mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents:
4119
diff
changeset
|
46 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
|
47 |
4093
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 app = query_params.c and site_apps[query_params.c]; |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 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
|
59 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 local register_page_template = assert(module:load_resource("html/register.html")):read("*a"); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 local error_template = assert(module:load_resource("html/register_error.html")):read("*a"); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 |
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 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
|
71 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
|
72 return { |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 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
|
74 headers = { |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 ["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
|
76 }; |
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 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 |
4129
ca099bd28bf5
mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents:
4119
diff
changeset
|
80 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
|
81 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 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
|
92 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
|
93 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 -- 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
|
97 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
|
98 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
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 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
|
109 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
|
110 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 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
|
123 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
|
124 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 }; |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 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
|
136 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 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
|
146 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 validated_invite = invite; |
4119
559ca8d93302
mod_invites_register_web: Also add ip to user-registered
Matthew Wild <mwild1@gmail.com>
parents:
4117
diff
changeset
|
153 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
|
154 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 |
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 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
|
157 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 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
|
159 if app_info then |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 -- If recognised app, we serve a page that includes setup instructions |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 success_template = assert(module:load_resource("html/register_success_setup.html")):read("*a"); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 else |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 success_template = assert(module:load_resource("html/register_success.html")):read("*a"); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 end |
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 -- 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
|
167 -- 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
|
168 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
|
169 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
|
170 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
|
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 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 else |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 }); |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 end |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 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
|
192 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
|
193 route = { |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 ["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
|
195 ["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
|
196 }; |
a2116f5a7c8f
mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 }); |