Mercurial > prosody-modules
comparison mod_invites_adhoc/mod_invites_adhoc.lua @ 4092:2b6918714792
mod_invites_adhoc: New module to allow invite creation via ad-hoc commands (XEP-0401)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 11 Sep 2020 13:50:47 +0100 |
parents | |
children | df9bb3d861f9 |
comparison
equal
deleted
inserted
replaced
4091:354dc1e7977a | 4092:2b6918714792 |
---|---|
1 -- XEP-0401: Easy User Onboarding | |
2 local dataforms = require "util.dataforms"; | |
3 local datetime = require "util.datetime"; | |
4 local split_jid = require "util.jid".split; | |
5 | |
6 local new_adhoc = module:require("adhoc").new; | |
7 | |
8 -- Whether local users can invite other users to create an account on this server | |
9 local allow_user_invites = module:get_option_boolean("allow_user_invites", false); | |
10 -- Who can see and use the contact invite command. It is strongly recommended to | |
11 -- keep this available to all local users. To allow/disallow invite-registration | |
12 -- on the server, use the option above instead. | |
13 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true); | |
14 | |
15 local invites; | |
16 if prosody.shutdown then -- COMPAT hack to detect prosodyctl | |
17 invites = module:depends("invites"); | |
18 end | |
19 | |
20 local invite_result_form = dataforms.new({ | |
21 title = "Your invite has been created", | |
22 { | |
23 name = "url" ; | |
24 var = "landing-url"; | |
25 label = "Invite web page"; | |
26 desc = "Share this link"; | |
27 }, | |
28 { | |
29 name = "uri"; | |
30 label = "Invite URI"; | |
31 desc = "This alternative link can be opened with some XMPP clients"; | |
32 }, | |
33 { | |
34 name = "expire"; | |
35 label = "Invite valid until"; | |
36 }, | |
37 }); | |
38 | |
39 module:depends("adhoc"); | |
40 | |
41 -- This command is available to all local users, even if allow_user_invites = false | |
42 -- If allow_user_invites is false, creating an invite still works, but the invite will | |
43 -- not be valid for registration on the current server, only for establishing a roster | |
44 -- subscription. | |
45 module:provides("adhoc", new_adhoc("Create new contact invite", "urn:xmpp:invite#invite", | |
46 function (_, data) | |
47 local username = split_jid(data.from); | |
48 local invite = invites.create_contact(username, allow_user_invites); | |
49 --TODO: check errors | |
50 return { | |
51 status = "completed"; | |
52 form = { | |
53 layout = invite_result_form; | |
54 values = { | |
55 uri = invite.uri; | |
56 url = invite.landing_page; | |
57 expire = datetime.datetime(invite.expires); | |
58 }; | |
59 }; | |
60 }; | |
61 end, allow_contact_invites and "local_user" or "admin")); | |
62 | |
63 -- This is an admin-only command that creates a new invitation suitable for registering | |
64 -- a new account. It does not add the new user to the admin's roster. | |
65 module:provides("adhoc", new_adhoc("Create new account invite", "urn:xmpp:invite#create-account", | |
66 function () | |
67 local invite = invites.create_account(); | |
68 --TODO: check errors | |
69 return { | |
70 status = "completed"; | |
71 form = { | |
72 layout = invite_result_form; | |
73 values = { | |
74 uri = invite.uri; | |
75 url = invite.landing_page; | |
76 expire = datetime.datetime(invite.expires); | |
77 }; | |
78 }; | |
79 }; | |
80 end, "admin")); |