comparison mod_invites_register_web/mod_invites_register_web.lua @ 6227:29a646bad096

mod_invites_register_web: Allow pointing other HTML templates Follows how some other modules allow overriding templates.
author Kim Alvefur <zash@zash.se>
date Thu, 22 May 2025 23:40:23 +0200
parents 15cf32e666da
children 6216d85162dc
comparison
equal deleted inserted replaced
6226:b3489b046782 6227:29a646bad096
32 module:depends("http"); 32 module:depends("http");
33 33
34 local invites = module:depends("invites"); 34 local invites = module:depends("invites");
35 local invites_page = module:depends("invites_page"); 35 local invites_page = module:depends("invites_page");
36 36
37 local template_path = module:get_option_path("invites_register_template_path", "html");
37 function serve_register_page(event) 38 function serve_register_page(event)
38 local register_page_template = assert(module:load_resource("html/register.html")):read("*a"); 39 local register_page_template = assert(module:load_resource(template_path .. "/register.html")):read("*a");
39 40
40 local query_params = event.request.url.query and http_formdecode(event.request.url.query); 41 local query_params = event.request.url.query and http_formdecode(event.request.url.query);
41 42
42 local invite = query_params and invites.get(query_params.t); 43 local invite = query_params and invites.get(query_params.t);
43 if not invite then 44 if not invite then
69 local request, response = event.request, event.response; 70 local request, response = event.request, event.response;
70 local form_data = http_formdecode(request.body); 71 local form_data = http_formdecode(request.body);
71 local user, password, token = form_data["user"], form_data["password"], form_data["token"]; 72 local user, password, token = form_data["user"], form_data["password"], form_data["token"];
72 local app_id = form_data["app_id"]; 73 local app_id = form_data["app_id"];
73 74
74 local register_page_template = assert(module:load_resource("html/register.html")):read("*a"); 75 local register_page_template = assert(module:load_resource(template_path .. "/register.html")):read("*a");
75 local error_template = assert(module:load_resource("html/register_error.html")):read("*a"); 76 local error_template = assert(module:load_resource(template_path .. "/register_error.html")):read("*a");
76 77
77 local invite = invites.get(token); 78 local invite = invites.get(token);
78 if not invite then 79 if not invite then
79 return { 80 return {
80 status_code = 303; 81 status_code = 303;
199 ["Location"] = redirect_url; 200 ["Location"] = redirect_url;
200 }; 201 };
201 }; 202 };
202 end 203 end
203 -- If recognised app, we serve a page that includes setup instructions 204 -- If recognised app, we serve a page that includes setup instructions
204 success_template = assert(module:load_resource("html/register_success_setup.html")):read("*a"); 205 success_template = assert(module:load_resource(template_path .. "/register_success_setup.html")):read("*a");
205 else 206 else
206 success_template = assert(module:load_resource("html/register_success.html")):read("*a"); 207 success_template = assert(module:load_resource(template_path .. "/register_success.html")):read("*a");
207 end 208 end
208 209
209 -- Due to the credentials being served here, ensure that 210 -- Due to the credentials being served here, ensure that
210 -- the browser or any intermediary does not cache the page 211 -- the browser or any intermediary does not cache the page
211 event.response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"; 212 event.response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate";