comparison plugins/mod_invites.lua @ 13613:9cd5b3484a1d

mod_invites: Add support for invites_page option to use external invites pages This allows Prosody to easily provide friendly invitation links, even without setting up mod_invites_page (which is a community module). Admins can configure it to use a third-party deployment such as https://xmpp.link or they can deploy their own based on https://github.com/modernxmpp/easy-xmpp-invitation Alternatively they can just install mod_invites_page and this will all be handled automatically by that.
author Matthew Wild <mwild1@gmail.com>
date Thu, 09 Jan 2025 13:23:46 +0000
parents 662dfff658a0
children a186f1cfae75
comparison
equal deleted inserted replaced
13612:8617f5962e47 13613:9cd5b3484a1d
3 local url = require "socket.url"; 3 local url = require "socket.url";
4 local jid_node = require "prosody.util.jid".node; 4 local jid_node = require "prosody.util.jid".node;
5 local jid_split = require "prosody.util.jid".split; 5 local jid_split = require "prosody.util.jid".split;
6 local argparse = require "prosody.util.argparse"; 6 local argparse = require "prosody.util.argparse";
7 local human_io = require "prosody.util.human.io"; 7 local human_io = require "prosody.util.human.io";
8
9 local url_escape = require "util.http".urlencode;
10 local render_url = require "util.interpolation".new("%b{}", url_escape, {
11 urlescape = url_escape;
12 noscheme = function (urlstring)
13 return (urlstring:gsub("^[^:]+:", ""));
14 end;
15 });
8 16
9 local default_ttl = module:get_option_period("invite_expiry", "1 week"); 17 local default_ttl = module:get_option_period("invite_expiry", "1 week");
10 18
11 local token_storage; 19 local token_storage;
12 if prosody.process_type == "prosody" or prosody.shutdown then 20 if prosody.process_type == "prosody" or prosody.shutdown then
200 function use(token) --luacheck: ignore 131/use 208 function use(token) --luacheck: ignore 131/use
201 local invite = get(token); 209 local invite = get(token);
202 return invite and invite:use(); 210 return invite and invite:use();
203 end 211 end
204 212
213 -- Point at e.g. a deployment of https://github.com/modernxmpp/easy-xmpp-invitation
214 -- This URL must always be absolute, as it is shared standalone
215 local invite_url_template = module:get_option_string("invites_page");
216 local invites_page_supports = module:get_option_set("invites_page_supports", { "account", "contact", "account-and-contact" });
217
218 local function add_landing_url(invite)
219 if not invite_url_template or invite.landing_page then return; end
220
221 -- Determine whether this type of invitation is supported by the landing page
222 local invite_type;
223 if invite.type == "register" then
224 invite_type = "account";
225 elseif invite.type == "roster" then
226 if invite.allow_registration then
227 invite_type = "account-and-contact";
228 else
229 invite_type = "contact-only";
230 end
231 end
232 if not invites_page_supports:contains(invite_type) then
233 return; -- Invitation type unsupported
234 end
235
236 invite.landing_page = render_url(invite_url_template, { host = module.host, invite = invite });
237 end
238
239 module:hook("invite-created", add_landing_url, -1);
240
205 --- shell command 241 --- shell command
206 module:add_item("shell-command", { 242 module:add_item("shell-command", {
207 section = "invite"; 243 section = "invite";
208 section_desc = "Create and manage invitations"; 244 section_desc = "Create and manage invitations";
209 name = "create_account"; 245 name = "create_account";