annotate mod_easy_invite/mod_easy_invite.lua @ 4813:0a257d1402c3

mod_muc_rtbl: Optimize case with zero hashes On the assumption that during quiet times between torrents of spam, the hash set would be empty. There would be no point in doing the operations and hashes to check for a match in that case.
author Kim Alvefur <zash@zash.se>
date Mon, 06 Dec 2021 18:19:19 +0100
parents 439ae12bb136
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- XEP-0401: Easy User Onboarding
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local dataforms = require "util.dataforms";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local datetime = require "util.datetime";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local jid_bare = require "util.jid".bare;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local jid_split = require "util.jid".split;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local split_jid = require "util.jid".split;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local rostermanager = require "core.rostermanager";
4088
439ae12bb136 mod_easy_invite: Remove hard dependency on mod_invites_page and allow configuration of different landing page module
Matthew Wild <mwild1@gmail.com>
parents: 4086
diff changeset
8 local modulemanager = require "core.modulemanager";
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local st = require "util.stanza";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local invite_only = module:get_option_boolean("registration_invite_only", true);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local require_encryption = module:get_option_boolean("c2s_require_encryption",
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 module:get_option_boolean("require_encryption", false));
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local new_adhoc = module:require("adhoc").new;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 -- Whether local users can invite other users to create an account on this server
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local allow_user_invites = module:get_option_boolean("allow_user_invites", true);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
3778
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
20 local invites;
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
21 if prosody.shutdown then -- COMPAT hack to detect prosodyctl
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
22 invites = module:depends("invites");
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
23 end
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local invite_result_form = dataforms.new({
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 title = "Your Invite",
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 -- TODO instructions = something helpful
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 {
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 name = "uri";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 label = "Invite URI";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 -- TODO desc = something helpful
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 },
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 {
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 name = "url" ;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 var = "landing-url";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 label = "Invite landing URL";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 },
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 {
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 name = "expire";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 label = "Token valid until";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 },
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 });
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 module:depends("adhoc");
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 module:provides("adhoc", new_adhoc("New Invite", "urn:xmpp:invite#invite",
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 function (_, data)
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 local username = split_jid(data.from);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 local invite = invites.create_contact(username, allow_user_invites);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 --TODO: check errors
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 return {
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 status = "completed";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 form = {
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 layout = invite_result_form;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 values = {
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 uri = invite.uri;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 url = invite.landing_page;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 expire = datetime.datetime(invite.expires);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 };
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 };
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 };
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 end, "local_user"));
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 -- TODO
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 -- module:provides("adhoc", new_adhoc("Create account", "urn:xmpp:invite#create-account", function () end, "admin"));
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 -- XEP-0379: Pre-Authenticated Roster Subscription
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 module:hook("presence/bare", function (event)
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 local stanza = event.stanza;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 if stanza.attr.type ~= "subscribe" then return end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 local preauth = stanza:get_child("preauth", "urn:xmpp:pars:0");
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 if not preauth then return end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 local token = preauth.attr.token;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 if not token then return end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 local username, host = jid_split(stanza.attr.to);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 local invite, err = invites.get(token, username);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 if not invite then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 module:log("debug", "Got invalid token, error: %s", err);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 return;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 local contact = jid_bare(stanza.attr.from);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 module:log("debug", "Approving inbound subscription to %s from %s", username, contact);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 if rostermanager.set_contact_pending_in(username, host, contact, stanza) then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 if rostermanager.subscribed(username, host, contact) then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 invite:use();
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 rostermanager.roster_push(username, host, contact);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 -- Send back a subscription request (goal is mutual subscription)
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 if not rostermanager.is_user_subscribed(username, host, contact)
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 and not rostermanager.is_contact_pending_out(username, host, contact) then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 module:log("debug", "Sending automatic subscription request to %s from %s", contact, username);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 if rostermanager.set_contact_pending_out(username, host, contact) then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 rostermanager.roster_push(username, host, contact);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 module:send(st.presence({type = "subscribe", to = contact }));
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 else
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 module:log("warn", "Failed to set contact pending out for %s", username);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 end, 1);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 -- TODO sender side, magic automatic mutual subscription
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 local invite_stream_feature = st.stanza("register", { xmlns = "urn:xmpp:invite" }):up();
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 module:hook("stream-features", function(event)
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 local session, features = event.origin, event.features;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 -- Advertise to unauthorized clients only.
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 if session.type ~= "c2s_unauthed" or (require_encryption and not session.secure) then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 return
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 features:add_child(invite_stream_feature);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 end);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 -- Client is submitting a preauth token to allow registration
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 module:hook("stanza/iq/urn:xmpp:pars:0:preauth", function(event)
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 local preauth = event.stanza.tags[1];
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 local token = preauth.attr.token;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 local validated_invite = invites.get(token);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 if not validated_invite then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 local reply = st.error_reply(event.stanza, "cancel", "forbidden", "The invite token is invalid or expired");
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 event.origin.send(reply);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 return true;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 event.origin.validated_invite = validated_invite;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 local reply = st.reply(event.stanza);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 event.origin.send(reply);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 return true;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 end);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 -- Registration attempt - ensure a valid preauth token has been supplied
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 module:hook("user-registering", function (event)
4023
7e2db4d61f6c mod_easy_invite: backport: ensure session exists before accessing it
Maxime “pep” Buquet <pep@bouah.net>
parents: 4022
diff changeset
141 local validated_invite = event.validated_invite or (event.session and event.session.validated_invite);
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 if invite_only and not validated_invite then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 event.allowed = false;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 event.reason = "Registration on this server is through invitation only";
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 return;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 end
4085
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
147 if validated_invite.additional_data and validated_invite.additional_data.allow_reset then
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
148 event.allow_reset = validated_invite.additional_data.allow_reset;
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
149 end
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 end);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 -- Make a *one-way* subscription. User will see when contact is online,
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 -- contact will not see when user is online.
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 function subscribe(host, user_username, contact_username)
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 local user_jid = user_username.."@"..host;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 local contact_jid = contact_username.."@"..host;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 -- Update user's roster to say subscription request is pending...
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 rostermanager.set_contact_pending_out(user_username, host, contact_jid);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 -- Update contact's roster to say subscription request is pending...
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 rostermanager.set_contact_pending_in(contact_username, host, user_jid);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 -- Update contact's roster to say subscription request approved...
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 rostermanager.subscribed(contact_username, host, user_jid);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 -- Update user's roster to say subscription request approved...
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 rostermanager.process_inbound_subscription_approval(user_username, host, contact_jid);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 -- Make a mutual subscription between jid1 and jid2. Each JID will see
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 -- when the other one is online.
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 function subscribe_both(host, user1, user2)
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 subscribe(host, user1, user2);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 subscribe(host, user2, user1);
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 -- Registration successful, if there was a preauth token, mark it as used
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 module:hook("user-registered", function (event)
4023
7e2db4d61f6c mod_easy_invite: backport: ensure session exists before accessing it
Maxime “pep” Buquet <pep@bouah.net>
parents: 4022
diff changeset
176 local validated_invite = event.validated_invite or (event.session and event.session.validated_invite);
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 if not validated_invite then
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 return;
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179 end
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 local inviter_username = validated_invite.inviter;
4082
6cdbca89b8be mod_easy_invite: Minor refactoring to begin merging additional changes from Snikket
Matthew Wild <mwild1@gmail.com>
parents: 4023
diff changeset
181 local contact_username = event.username;
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 validated_invite:use();
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183
4082
6cdbca89b8be mod_easy_invite: Minor refactoring to begin merging additional changes from Snikket
Matthew Wild <mwild1@gmail.com>
parents: 4023
diff changeset
184 if inviter_username then
6cdbca89b8be mod_easy_invite: Minor refactoring to begin merging additional changes from Snikket
Matthew Wild <mwild1@gmail.com>
parents: 4023
diff changeset
185 module:log("debug", "Creating mutual subscription between %s and %s", inviter_username, contact_username);
6cdbca89b8be mod_easy_invite: Minor refactoring to begin merging additional changes from Snikket
Matthew Wild <mwild1@gmail.com>
parents: 4023
diff changeset
186 subscribe_both(module.host, inviter_username, contact_username);
6cdbca89b8be mod_easy_invite: Minor refactoring to begin merging additional changes from Snikket
Matthew Wild <mwild1@gmail.com>
parents: 4023
diff changeset
187 end
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188
4084
9d11c18d4d7e mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4083
diff changeset
189 if validated_invite.additional_data then
9d11c18d4d7e mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4083
diff changeset
190 module:log("debug", "Importing roles from invite");
9d11c18d4d7e mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4083
diff changeset
191 local roles = validated_invite.additional_data.roles;
9d11c18d4d7e mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4083
diff changeset
192 if roles then
9d11c18d4d7e mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4083
diff changeset
193 module:open_store("roles"):set(contact_username, roles);
9d11c18d4d7e mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4083
diff changeset
194 end
9d11c18d4d7e mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4083
diff changeset
195 end
9d11c18d4d7e mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4083
diff changeset
196 end);
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197
4085
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
198 -- Equivalent of user-registered but for when the account already existed
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
199 -- (i.e. password reset)
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
200 module:hook("user-password-reset", function (event)
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
201 local validated_invite = event.validated_invite or (event.session and event.session.validated_invite);
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
202 if not validated_invite then
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
203 return;
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
204 end
fe75cc43dfbf mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents: 4084
diff changeset
205 validated_invite:use();
3777
26559776a87e mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 end);
3778
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
207
4022
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
208 do
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
209 -- Telnet command
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
210 -- Since the telnet console is global this overwrites the command for
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
211 -- each host it's loaded on, but this should be fine.
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
212
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
213 local get_module = require "core.modulemanager".get_module;
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
214
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
215 local console_env = module:shared("/*/admin_telnet/env");
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
216
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
217 -- luacheck: ignore 212/self
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
218 console_env.invite = {};
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
219 function console_env.invite:create_account(user_jid)
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
220 local username, host = jid_split(user_jid);
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
221 local mod_invites, err = get_module(host, "invites");
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
222 if not mod_invites then return nil, err or "mod_invites not loaded on this host"; end
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
223 local invite, err = mod_invites.create_account(username);
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
224 if not invite then return nil, err; end
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
225 return true, invite.uri;
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
226 end
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
227
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
228 function console_env.invite:create_contact(user_jid, allow_registration)
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
229 local username, host = jid_split(user_jid);
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
230 local mod_invites, err = get_module(host, "invites");
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
231 if not mod_invites then return nil, err or "mod_invites not loaded on this host"; end
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
232 local invite, err = mod_invites.create_contact(username, allow_registration);
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
233 if not invite then return nil, err; end
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
234 return true, invite.uri;
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
235 end
3ac31ddab7eb mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents: 3788
diff changeset
236 end
3778
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
237
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
238 local sm = require "core.storagemanager";
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
239 function module.command(arg)
3788
14028430638b mod_easy_invite: Change command name to 'generate' (from 'register')
Matthew Wild <mwild1@gmail.com>
parents: 3778
diff changeset
240 if #arg < 2 or arg[2] ~= "generate" then
14028430638b mod_easy_invite: Change command name to 'generate' (from 'register')
Matthew Wild <mwild1@gmail.com>
parents: 3778
diff changeset
241 print("usage: prosodyctl mod_easy_invite example.net generate");
3778
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
242 return;
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
243 end
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
244
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
245 local host = arg[1];
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
246 assert(hosts[host], "Host "..tostring(host).." does not exist");
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
247 sm.initialize_host(host);
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
248
4083
e7eb46d976ae mod_easy_invite: Add code comment (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4082
diff changeset
249 -- Load mod_invites
3778
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
250 invites = module:context(host):depends("invites");
4088
439ae12bb136 mod_easy_invite: Remove hard dependency on mod_invites_page and allow configuration of different landing page module
Matthew Wild <mwild1@gmail.com>
parents: 4086
diff changeset
251 local invites_page_module = module:context(host):get_option_string("easy_invite_page_module", "invites_page");
439ae12bb136 mod_easy_invite: Remove hard dependency on mod_invites_page and allow configuration of different landing page module
Matthew Wild <mwild1@gmail.com>
parents: 4086
diff changeset
252 if modulemanager.get_modules_for_host(host):contains(invites_page_module) then
439ae12bb136 mod_easy_invite: Remove hard dependency on mod_invites_page and allow configuration of different landing page module
Matthew Wild <mwild1@gmail.com>
parents: 4086
diff changeset
253 module:context(host):depends(invites_page_module);
439ae12bb136 mod_easy_invite: Remove hard dependency on mod_invites_page and allow configuration of different landing page module
Matthew Wild <mwild1@gmail.com>
parents: 4086
diff changeset
254 end
4086
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
255
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
256 table.remove(arg, 1);
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
257 table.remove(arg, 1);
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
258
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
259 local invite, roles;
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
260 if arg[1] == "--reset" then
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
261 local nodeprep = require "util.encodings".stringprep.nodeprep;
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
262 local username = nodeprep(arg[2]);
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
263 if not username then
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
264 print("Please supply a valid username to generate a reset link for");
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
265 return;
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
266 end
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
267 invite = invites.create_account_reset(username);
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
268 else
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
269 if arg[1] == "--admin" then
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
270 roles = { ["prosody:admin"] = true };
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
271 elseif arg[1] == "--role" then
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
272 roles = { [arg[2]] = true };
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
273 end
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
274 invite = invites.create_account(nil, { roles = roles });
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
275 end
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
276
50644402c6f5 mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents: 4085
diff changeset
277 print(invite.landing_page or invite.uri);
3778
7209f481bcfe mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
278 end