Mercurial > prosody-modules
annotate mod_invites_page/mod_invites_page.lua @ 6195:dfdf0bf1e84f
mod_invites_page: Remove compatibility with 0.11
| author | Link Mauve <linkmauve@linkmauve.fr> |
|---|---|
| date | Wed, 09 Apr 2025 19:05:14 +0200 |
| parents | efdaffc878a9 |
| children | d68e640e76ad |
| 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; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
|
4408
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
4 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
|
5 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 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
|
7 urlescape = url_escape; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 lower = string.lower; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 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
|
10 relurl = function (s) |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 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
|
12 return s; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 return base_url.."/"..s; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 }); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 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
|
18 urlescape = url_escape; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 noscheme = function (url) |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 return (url:gsub("^[^:]+:", "")); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 }); |
|
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 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
|
25 local site_apps; |
|
4094
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
|
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
|
27 -- 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
|
28 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
|
29 |
|
4094
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local http_files; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 |
|
4408
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
32 if not external_only then |
|
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
33 -- Load HTTP-serving dependencies |
|
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
34 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
|
35 module:depends("http"); |
|
6195
dfdf0bf1e84f
mod_invites_page: Remove compatibility with 0.11
Link Mauve <linkmauve@linkmauve.fr>
parents:
5620
diff
changeset
|
36 http_files = require "net.http.files"; |
|
5620
efdaffc878a9
mod_invites_page: Produce URL without config from prosodyctl in trunk
Kim Alvefur <zash@zash.se>
parents:
4976
diff
changeset
|
37 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
|
38 module:depends("http"); |
|
efdaffc878a9
mod_invites_page: Produce URL without config from prosodyctl in trunk
Kim Alvefur <zash@zash.se>
parents:
4976
diff
changeset
|
39 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
|
40 end |
|
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
41 -- Calculate automatic base_url default |
|
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
42 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
|
43 |
|
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
44 -- Load site apps info |
|
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
45 module:depends("register_apps"); |
|
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
46 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
|
47 end |
|
4408
2c47b8110c48
mod_invites_page: Some fixes for external-only mode
Matthew Wild <mwild1@gmail.com>
parents:
4402
diff
changeset
|
48 |
|
4094
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 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
|
50 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 -- 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
|
52 -- 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
|
53 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
|
54 -- 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
|
55 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
|
56 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 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
|
58 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
|
59 -- 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
|
60 -- 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
|
61 -- 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
|
62 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
|
63 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
|
64 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 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
|
67 |
|
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
|
68 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
|
69 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
|
70 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
|
71 |
|
4094
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 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
|
73 local rendered_apps = {}; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 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
|
78 -- 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
|
79 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
|
80 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
|
81 -- 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
|
82 -- click the URI button |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 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
|
84 else |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 -- 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
|
86 -- 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
|
87 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
|
88 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 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
|
90 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 return rendered_apps; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 function serve_invite_page(event) |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 local invite_page_template = assert(module:load_resource("html/invite.html")):read("*a"); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 local invalid_invite_page_template = assert(module:load_resource("html/invite_invalid.html")):read("*a"); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 |
|
4129
ca099bd28bf5
mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents:
4116
diff
changeset
|
98 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
|
99 |
|
4094
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 local invite = invites.get(event.request.url.query); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 if not invite then |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 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
|
103 site_name = site_name; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 static = base_url.."/static"; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 }); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 local template_vars = { |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 site_name = site_name; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 token = invite.token; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 uri = invite.uri; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 type = invite.type; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 jid = invite.jid; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 inviter = invite.inviter; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 static = base_url.."/static"; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 }; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 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
|
118 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 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
|
120 |
|
05d0a249326a
mod_invites_page: Add Link header for URI with rel=alternate
Matthew Wild <mwild1@gmail.com>
parents:
4107
diff
changeset
|
121 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
|
122 return invite_page; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 function serve_setup_page(event, app_id) |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 local invite_page_template = assert(module:load_resource("html/client.html")):read("*a"); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 local invalid_invite_page_template = assert(module:load_resource("html/invite_invalid.html")):read("*a"); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 |
|
4129
ca099bd28bf5
mod_invites_page, mod_invites_register_web: Set correct Content-Type everywhere necessary
Matthew Wild <mwild1@gmail.com>
parents:
4116
diff
changeset
|
129 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
|
130 |
|
4094
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 local invite = invites.get(event.request.url.query); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 if not invite then |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 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
|
134 site_name = site_name; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 static = base_url.."/static"; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 }); |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 local template_vars = { |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 site_name = site_name; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 apps = site_apps; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 token = invite.token; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 uri = invite.uri; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 type = invite.type; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 jid = invite.jid; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 static = base_url.."/static"; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 }; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 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
|
149 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 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
|
151 return invite_page; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 end |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 local mime_map = { |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 png = "image/png"; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 svg = "image/svg+xml"; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 js = "application/javascript"; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 }; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 module:provides("http", { |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 route = { |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 ["GET"] = serve_invite_page; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 ["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
|
164 ["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
|
165 }; |
|
dd00a2b9927c
mod_invites_page: New module to generate landing page for invites
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 }); |
