Software /
code /
prosody-modules
Changeset
5589:c362833be557
mod_invites_register_web: Add html template and URL configuration for multiple (human) language.
author | Trần H. Trung <work@trung.fun> |
---|---|
date | Fri, 26 May 2023 01:37:08 +0700 |
parents | 5588:f16720087ef2 |
children | 5590:d5a31a13c357 |
files | mod_invites_register_web/mod_invites_register_web.lua |
diffstat | 1 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_invites_register_web/mod_invites_register_web.lua Tue May 23 23:45:00 2023 +0700 +++ b/mod_invites_register_web/mod_invites_register_web.lua Fri May 26 01:37:08 2023 +0700 @@ -34,10 +34,17 @@ local invites = module:depends("invites"); local invites_page = module:depends("invites_page"); +local templatePath = module:get_option_string("invites_html_template", "html"); +function template_get(sTemplate, sLang) + local template = sLang and templatePath.."/"..sTemplate.."."..sLang..".html" + or templatePath.."/"..sTemplate..".html"; + return assert(module:load_resource(template):read("*a")); +end + +local lang = nil; function serve_register_page(event) - local register_page_template = assert(module:load_resource("html/register.html")):read("*a"); - local query_params = event.request.url.query and http_formdecode(event.request.url.query); + lang = query_params and query_params.l; local invite = query_params and invites.get(query_params.t); if not invite then @@ -49,6 +56,7 @@ }; end + local register_page_template = template_get("register", lang); event.response.headers["Content-Type"] = "text/html; charset=utf-8"; local invite_page = render_html_template(register_page_template, { @@ -71,8 +79,8 @@ local user, password, token = form_data["user"], form_data["password"], form_data["token"]; local app_id = form_data["app_id"]; - local register_page_template = assert(module:load_resource("html/register.html")):read("*a"); - local error_template = assert(module:load_resource("html/register_error.html")):read("*a"); + local register_page_template = template_get("register", lang); + local error_template = template_get("register_error", lang); local invite = invites.get(token); if not invite then @@ -201,9 +209,9 @@ }; end -- If recognised app, we serve a page that includes setup instructions - success_template = assert(module:load_resource("html/register_success_setup.html")):read("*a"); + success_template = template_get("register_success_setup", lang); else - success_template = assert(module:load_resource("html/register_success.html")):read("*a"); + success_template = template_get("register_success", lang); end -- Due to the credentials being served here, ensure that