# HG changeset patch # User Trần H. Trung # Date 1693322701 -25200 # Node ID ebc09159b94ac794eb2f3416f9b0bb2c06ad6188 # Parent e76ec7ad941e200b8d8bf9651ed61aa34e38beaa mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly. diff -r e76ec7ad941e -r ebc09159b94a mod_invites_page/mod_invites_page.lua --- a/mod_invites_page/mod_invites_page.lua Tue Aug 29 22:06:19 2023 +0700 +++ b/mod_invites_page/mod_invites_page.lua Tue Aug 29 22:25:01 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;