Annotate

mod_invites_page/mod_invites_page.lua @ 5662:ebc09159b94a

mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Tue, 29 Aug 2023 22:25:01 +0700
parent 5630:efdaffc878a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local st = require "util.stanza";
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local url_escape = require "util.http".urlencode;
5662
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
3 local http_formdecode = require "net.http".formdecode;
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
4408
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
5 local base_url = "https://"..module.host.."/";
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local render_html_template = require"util.interpolation".new("%b{}", st.xml_escape, {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 urlescape = url_escape;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 lower = string.lower;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 classname = function (s) return (s:gsub("%W+", "-")); end;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 relurl = function (s)
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 if s:match("^%w+://") then
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 return s;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 return base_url.."/"..s;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 });
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local render_url = require "util.interpolation".new("%b{}", url_escape, {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 urlescape = url_escape;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 noscheme = function (url)
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 return (url:gsub("^[^:]+:", ""));
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 });
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local site_name = module:get_option_string("site_name", module.host);
4408
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
26 local site_apps;
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
4402
85c11eb4331b mod_invites_page: Allow disabling of built-in pages with invites_page_external option
Matthew Wild <mwild1@gmail.com>
parents: 4129
diff changeset
28 -- Enable/disable built-in invite pages
85c11eb4331b mod_invites_page: Allow disabling of built-in pages with invites_page_external option
Matthew Wild <mwild1@gmail.com>
parents: 4129
diff changeset
29 local external_only = module:get_option_boolean("invites_page_external", false);
85c11eb4331b mod_invites_page: Allow disabling of built-in pages with invites_page_external option
Matthew Wild <mwild1@gmail.com>
parents: 4129
diff changeset
30
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local http_files;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
4408
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
33 if not external_only then
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
34 -- Load HTTP-serving dependencies
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
35 if prosody.shutdown then -- not if running under prosodyctl
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
36 module:depends("http");
4976
75b6e5df65f9 various: Improve error reporting if missing file server module on 0.12
Kim Alvefur <zash@zash.se>
parents: 4975
diff changeset
37
75b6e5df65f9 various: Improve error reporting if missing file server module on 0.12
Kim Alvefur <zash@zash.se>
parents: 4975
diff changeset
38 if prosody.process_type == "prosody" then
4975
733e5513f691 various: Use 0.12+ API for serving files from the file system over HTTP
Kim Alvefur <zash@zash.se>
parents: 4408
diff changeset
39 http_files = require "net.http.files";
4976
75b6e5df65f9 various: Improve error reporting if missing file server module on 0.12
Kim Alvefur <zash@zash.se>
parents: 4975
diff changeset
40 else
4975
733e5513f691 various: Use 0.12+ API for serving files from the file system over HTTP
Kim Alvefur <zash@zash.se>
parents: 4408
diff changeset
41 http_files = module:depends"http_files";
733e5513f691 various: Use 0.12+ API for serving files from the file system over HTTP
Kim Alvefur <zash@zash.se>
parents: 4408
diff changeset
42 end
5630
efdaffc878a9 mod_invites_page: Produce URL without config from prosodyctl in trunk
Kim Alvefur <zash@zash.se>
parents: 4976
diff changeset
43 elseif prosody.process_type and module.get_option_period then
efdaffc878a9 mod_invites_page: Produce URL without config from prosodyctl in trunk
Kim Alvefur <zash@zash.se>
parents: 4976
diff changeset
44 module:depends("http");
efdaffc878a9 mod_invites_page: Produce URL without config from prosodyctl in trunk
Kim Alvefur <zash@zash.se>
parents: 4976
diff changeset
45 http_files = require "net.http.files";
4408
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
46 end
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
47 -- Calculate automatic base_url default
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
48 base_url = module.http_url and module:http_url();
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
49
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
50 -- Load site apps info
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
51 module:depends("register_apps");
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
52 site_apps = module:shared("register_apps/apps");
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 end
4408
2c47b8110c48 mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents: 4402
diff changeset
54
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 local invites = module:depends("invites");
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 -- Point at eg https://github.com/ge0rg/easy-xmpp-invitation
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 -- This URL must always be absolute, as it is shared standalone
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 local invite_url_template = module:get_option_string("invites_page", base_url and (base_url.."?{invite.token}") or nil);
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 -- This URL is relative to the invite page, or can be absolute
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 local register_url_template = module:get_option_string("invites_registration_page", "register?t={invite.token}&c={app.id}");
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 local function add_landing_url(invite)
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 if not invite_url_template then return; end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 -- TODO: we don't currently have a landing page for subscription-only invites,
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 -- so the user will only receive a URI. The client should be able to handle this
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 -- by automatically falling back to a client-specific landing page, per XEP-0401.
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 if not invite.allow_registration then return; end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 invite.landing_page = render_url(invite_url_template, { host = module.host, invite = invite });
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 module:hook("invite-created", add_landing_url);
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73
4402
85c11eb4331b mod_invites_page: Allow disabling of built-in pages with invites_page_external option
Matthew Wild <mwild1@gmail.com>
parents: 4129
diff changeset
74 if external_only then
85c11eb4331b mod_invites_page: Allow disabling of built-in pages with invites_page_external option
Matthew Wild <mwild1@gmail.com>
parents: 4129
diff changeset
75 return;
85c11eb4331b mod_invites_page: Allow disabling of built-in pages with invites_page_external option
Matthew Wild <mwild1@gmail.com>
parents: 4129
diff changeset
76 end
85c11eb4331b mod_invites_page: Allow disabling of built-in pages with invites_page_external option
Matthew Wild <mwild1@gmail.com>
parents: 4129
diff changeset
77
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 local function render_app_urls(apps, invite_vars)
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 local rendered_apps = {};
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 for _, unrendered_app in ipairs(apps) do
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 local app = setmetatable({}, { __index = unrendered_app });
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 local template_vars = { app = app, invite = invite_vars, base_url = base_url };
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 if app.magic_link_format then
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 -- Magic link generally links directly to third-party
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 app.proceed_url = render_url(app.magic_link_format or app.link or "#", template_vars);
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 elseif app.supports_preauth_uri then
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 -- Proceed to a page that guides the user to download, and then
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 -- click the URI button
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 app.proceed_url = render_url("{base_url!}/setup/{app.id}?{invite.token}", template_vars);
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 else
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 -- Manual means proceed to web registration, but include app id
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 -- so it can show post-registration instructions
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 app.proceed_url = render_url(register_url_template, template_vars);
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 table.insert(rendered_apps, app);
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 return rendered_apps;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99
5662
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
100 local templatePath = module:get_option_string("invites_template_html", "html");
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
101 local function template_get(filename, lang)
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
102 local template = lang and templatePath.."/"..filename.."."..lang..".html"
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
103 or templatePath.."/"..filename..".html";
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
104 return assert(module:load_resource(template):read("*a"));
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
105 end
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
106
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 function serve_invite_page(event)
5662
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
108 local query_params = event.request.url.query and http_formdecode(event.request.url.query);
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
109 local lang = query_params and query_params.l;
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
110
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
111 local invite_page_template = template_get("invite", lang);
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
112 local invalid_invite_page_template = template_get("invite_invalid", lang);
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113
4129
ca099bd28bf5 mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents: 4116
diff changeset
114 event.response.headers["Content-Type"] = "text/html; charset=utf-8";
ca099bd28bf5 mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents: 4116
diff changeset
115
5662
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
116 local invite = invites.get(event.request.url.query.t);
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 if not invite then
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 return render_html_template(invalid_invite_page_template, {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 site_name = site_name;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 static = base_url.."/static";
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 });
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 local template_vars = {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 site_name = site_name;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 token = invite.token;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 uri = invite.uri;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 type = invite.type;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 jid = invite.jid;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 inviter = invite.inviter;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 static = base_url.."/static";
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 };
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 template_vars.apps = render_app_urls(site_apps, template_vars);
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 local invite_page = render_html_template(invite_page_template, template_vars);
4116
05d0a249326a mod_invites_page: Add Link header for URI with rel=alternate
Matthew Wild <mwild1@gmail.com>
parents: 4107
diff changeset
136
05d0a249326a mod_invites_page: Add Link header for URI with rel=alternate
Matthew Wild <mwild1@gmail.com>
parents: 4107
diff changeset
137 event.response.headers["Link"] = ([[<%s>; rel="alternate"]]):format(template_vars.uri);
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 return invite_page;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 function serve_setup_page(event, app_id)
5662
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
142 local query_params = event.request.url.query and http_formdecode(event.request.url.query);
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
143 local lang = query_params and query_params.l;
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
144
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
145 local invite_page_template = template_get("client", lang);
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
146 local invalid_invite_page_template = template_get("invite_invalid", lang);
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147
4129
ca099bd28bf5 mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents: 4116
diff changeset
148 event.response.headers["Content-Type"] = "text/html; charset=utf-8";
ca099bd28bf5 mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents: 4116
diff changeset
149
5662
ebc09159b94a mod_invites_page: load `invites_template_html` from config which support multiple languages and parse the correct query params accordingly.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5630
diff changeset
150 local invite = invites.get(event.request.url.query.t);
4094
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 if not invite then
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 return render_html_template(invalid_invite_page_template, {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 site_name = site_name;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 static = base_url.."/static";
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 });
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 local template_vars = {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 site_name = site_name;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 apps = site_apps;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 token = invite.token;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 uri = invite.uri;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 type = invite.type;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 jid = invite.jid;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 static = base_url.."/static";
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 };
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 template_vars.app = render_app_urls({ site_apps[app_id] }, template_vars)[1];
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 local invite_page = render_html_template(invite_page_template, template_vars);
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 return invite_page;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 end
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 local mime_map = {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 png = "image/png";
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 svg = "image/svg+xml";
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 js = "application/javascript";
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 };
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179 module:provides("http", {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 route = {
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 ["GET"] = serve_invite_page;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 ["GET /setup/*"] = serve_setup_page;
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 ["GET /static/*"] = http_files and http_files.serve({ path = module:get_directory().."/static", mime_map = mime_map });
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 };
dd00a2b9927c mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 });