# HG changeset patch # User Trần H. Trung # Date 1693327877 -25200 # Node ID 52db2da66680381cd3083c8fbeeae3c62aded096 # Parent f6e8165a2ec2f1977d0748ed2acb61979fc4c150# Parent ebc09159b94ac794eb2f3416f9b0bb2c06ad6188 Merge local diff -r f6e8165a2ec2 -r 52db2da66680 mod_invites_page/mod_invites_page.lua --- 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; diff -r f6e8165a2ec2 -r 52db2da66680 mod_invites_register_web/README.markdown --- 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: diff -r f6e8165a2ec2 -r 52db2da66680 mod_invites_register_web/mod_invites_register_web.lua --- 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";