annotate mod_invites_register_web/mod_invites_register_web.lua @ 4129:ca099bd28bf5

mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
author Matthew Wild <mwild1@gmail.com>
date Tue, 15 Sep 2020 14:11:48 +0100
parents 559ca8d93302
children 3a03ae9a0882
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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";
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 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
5 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
6 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
7 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
8 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
9 });
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 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
13
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 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
15 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
16
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 module:depends("http");
4108
f49e3ea99785 mod_invites_register_web: Remove dependency on mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents: 4093
diff changeset
18
4093
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 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
20 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
21
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 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
23 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
24
4112
d0366474aace mod_invites_register_web: Fix traceback on missing query params
Matthew Wild <mwild1@gmail.com>
parents: 4108
diff changeset
25 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
26
4112
d0366474aace mod_invites_register_web: Fix traceback on missing query params
Matthew Wild <mwild1@gmail.com>
parents: 4108
diff changeset
27 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
28 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
29 return {
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 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
31 headers = {
4112
d0366474aace mod_invites_register_web: Fix traceback on missing query params
Matthew Wild <mwild1@gmail.com>
parents: 4108
diff changeset
32 ["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
33 };
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 };
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 end
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36
4129
ca099bd28bf5 mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents: 4119
diff changeset
37 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
38
4093
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 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
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 });
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 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
50 end
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 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
53 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
54 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
55 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
56 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
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 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
59 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
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 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
62 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
63 return {
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 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
65 headers = {
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 ["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
67 };
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 end
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70
4129
ca099bd28bf5 mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents: 4119
diff changeset
71 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
72
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
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 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
83 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
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 end
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 -- 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
88 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
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 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
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;
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 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
100 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
101 });
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 end
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
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 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
114 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
115 });
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 end
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 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
119 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
120 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
121 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
122 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
123 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
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
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 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
127
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 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
129 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
130 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
131 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
132 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
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 end
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 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
137
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 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
139 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
140 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
141 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
142 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
143 validated_invite = invite;
4119
559ca8d93302 mod_invites_register_web: Also add ip to user-registered
Matthew Wild <mwild1@gmail.com>
parents: 4117
diff changeset
144 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
145 });
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 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
148
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 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
150 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
151 -- 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
152 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
153 else
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 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
155 end
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 -- 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
158 -- 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
159 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
160 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
161 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
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 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
164 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
165 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
166 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
167 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
168 app = app_info;
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 });
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 else
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 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
172 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
173 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
174 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
175 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
176 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
177 });
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 end
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179 end
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 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
182 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
183 route = {
a2116f5a7c8f mod_invites_register_web: New module to allow web registration with an invite token
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 ["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
185 ["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
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 });