Changeset

5664:52db2da66680 draft

Merge local
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Tue, 29 Aug 2023 23:51:17 +0700
parents 5663:f6e8165a2ec2 (current diff) 5662:ebc09159b94a (diff)
children 5856:75dee6127829
files
diffstat 3 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mod_invites_page/mod_invites_page.lua	Tue Aug 29 22:46:27 2023 +0700
+++ b/mod_invites_page/mod_invites_page.lua	Tue Aug 29 23:51:17 2023 +0700
@@ -1,5 +1,6 @@
 local st = require "util.stanza";
 local url_escape = require "util.http".urlencode;
+local http_formdecode = require "net.http".formdecode;
 
 local base_url = "https://"..module.host.."/";
 
@@ -96,13 +97,23 @@
 	return rendered_apps;
 end
 
+local templatePath = module:get_option_string("invites_template_html", "html");
+local function template_get(filename, lang)
+	local template = lang and templatePath.."/"..filename.."."..lang..".html" 
+		or templatePath.."/"..filename..".html";
+	return assert(module:load_resource(template):read("*a"));
+end
+
 function serve_invite_page(event)
-	local invite_page_template = assert(module:load_resource("html/invite.html")):read("*a");
-	local invalid_invite_page_template = assert(module:load_resource("html/invite_invalid.html")):read("*a");
+	local query_params = event.request.url.query and http_formdecode(event.request.url.query);
+	local lang = query_params and query_params.l;
+
+	local invite_page_template = template_get("invite", lang);
+	local invalid_invite_page_template = template_get("invite_invalid", lang);
 
 	event.response.headers["Content-Type"] = "text/html; charset=utf-8";
 
-	local invite = invites.get(event.request.url.query);
+	local invite = invites.get(event.request.url.query.t);
 	if not invite then
 		return render_html_template(invalid_invite_page_template, {
 			site_name = site_name;
@@ -128,12 +139,15 @@
 end
 
 function serve_setup_page(event, app_id)
-	local invite_page_template = assert(module:load_resource("html/client.html")):read("*a");
-	local invalid_invite_page_template = assert(module:load_resource("html/invite_invalid.html")):read("*a");
+	local query_params = event.request.url.query and http_formdecode(event.request.url.query);
+	local lang = query_params and query_params.l;
+
+	local invite_page_template = template_get("client", lang);
+	local invalid_invite_page_template = template_get("invite_invalid", lang);
 
 	event.response.headers["Content-Type"] = "text/html; charset=utf-8";
 
-	local invite = invites.get(event.request.url.query);
+	local invite = invites.get(event.request.url.query.t);
 	if not invite then
 		return render_html_template(invalid_invite_page_template, {
 			site_name = site_name;
--- a/mod_invites_register_web/README.markdown	Tue Aug 29 22:46:27 2023 +0700
+++ b/mod_invites_register_web/README.markdown	Tue Aug 29 23:51:17 2023 +0700
@@ -52,7 +52,7 @@
 to after successful registration. If not specified but mod_conversejs is loaded
 on the current host, it will default to the URL of that module.
 
-You can use your own html templates with `invites_html_template`. Names of the
+You can use your own html templates with `invites_template_html`. Names of the
 files MUST match the default. More over, you can offer multiple (human)
 languages by adding the `&l=` to the URL. Meaning this module will serve
 `register.html` for your default URL:
--- a/mod_invites_register_web/mod_invites_register_web.lua	Tue Aug 29 22:46:27 2023 +0700
+++ b/mod_invites_register_web/mod_invites_register_web.lua	Tue Aug 29 23:51:17 2023 +0700
@@ -34,7 +34,7 @@
 local invites = module:depends("invites");
 local invites_page = module:depends("invites_page");
 
-local templatePath = module:get_option_string("invites_html_template", "html");
+local templatePath = module:get_option_string("invites_template_html", "html");
 function template_get(sTemplate, sLang)
 	local template = sLang and templatePath.."/"..sTemplate.."."..sLang..".html" 
 		or templatePath.."/"..sTemplate..".html";