author | Matthew Wild <mwild1@gmail.com> |
Mon, 07 Sep 2020 12:53:35 +0100 | |
changeset 4090 | 50644402c6f5 |
parent 4089 | fe75cc43dfbf |
child 4092 | 439ae12bb136 |
permissions | -rw-r--r-- |
3781
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"; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
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
|
9 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
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
|
11 |
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
|
12 |
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
|
13 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
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
|
15 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
-- 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
|
17 |
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
|
18 |
|
3782
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
19 |
local invites; |
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
20 |
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:
3781
diff
changeset
|
21 |
invites = module:depends("invites"); |
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
22 |
end |
3781
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
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
|
25 |
title = "Your Invite", |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
-- TODO instructions = something helpful |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
{ |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
name = "uri"; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
label = "Invite URI"; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
-- TODO desc = something helpful |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 |
}, |
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 |
name = "url" ; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
var = "landing-url"; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
label = "Invite landing URL"; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
}, |
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 |
name = "expire"; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 |
label = "Token valid until"; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
}, |
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 |
module:depends("adhoc"); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
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
|
45 |
function (_, data) |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 |
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
|
47 |
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
|
48 |
--TODO: check errors |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 |
return { |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 |
status = "completed"; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 |
form = { |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 |
layout = invite_result_form; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 |
values = { |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 |
uri = invite.uri; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 |
url = invite.landing_page; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 |
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
|
57 |
}; |
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 |
end, "local_user")); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 |
|
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 |
-- TODO |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 |
-- 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
|
65 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 |
-- 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
|
67 |
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
|
68 |
local stanza = event.stanza; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 |
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
|
70 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
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
|
77 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 |
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
|
79 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 |
if not invite then |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 |
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
|
82 |
return; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 |
end |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 |
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
|
86 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
invite:use(); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 |
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
|
92 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 |
-- 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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
else |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 |
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
|
102 |
end |
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, 1); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 |
-- 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
|
109 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 |
-- 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
|
115 |
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
|
116 |
return |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 |
end |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 |
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
|
120 |
end); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 |
-- 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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
event.origin.send(reply); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 |
return true; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 |
end |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 |
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
|
133 |
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
|
134 |
event.origin.send(reply); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 |
return true; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 |
end); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 |
-- 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
|
139 |
module:hook("user-registering", function (event) |
4027
7e2db4d61f6c
mod_easy_invite: backport: ensure session exists before accessing it
Maxime “pep” Buquet <pep@bouah.net>
parents:
4026
diff
changeset
|
140 |
local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); |
3781
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 |
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
|
142 |
event.allowed = false; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 |
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
|
144 |
return; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 |
end |
4089
fe75cc43dfbf
mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents:
4088
diff
changeset
|
146 |
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:
4088
diff
changeset
|
147 |
event.allow_reset = validated_invite.additional_data.allow_reset; |
fe75cc43dfbf
mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents:
4088
diff
changeset
|
148 |
end |
3781
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 |
end); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 |
-- 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
|
152 |
-- 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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
-- 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
|
157 |
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
|
158 |
-- 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
|
159 |
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
|
160 |
-- 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
|
161 |
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
|
162 |
-- 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
|
163 |
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
|
164 |
end |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 |
-- 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
|
167 |
-- 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
|
168 |
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
|
169 |
subscribe(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, user2, user1); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 |
end |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 |
|
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 |
-- 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
|
174 |
module:hook("user-registered", function (event) |
4027
7e2db4d61f6c
mod_easy_invite: backport: ensure session exists before accessing it
Maxime “pep” Buquet <pep@bouah.net>
parents:
4026
diff
changeset
|
175 |
local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); |
3781
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 |
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
|
177 |
return; |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 |
end |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 |
local inviter_username = validated_invite.inviter; |
4086
6cdbca89b8be
mod_easy_invite: Minor refactoring to begin merging additional changes from Snikket
Matthew Wild <mwild1@gmail.com>
parents:
4027
diff
changeset
|
180 |
local contact_username = event.username; |
3781
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 |
validated_invite:use(); |
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 |
|
4086
6cdbca89b8be
mod_easy_invite: Minor refactoring to begin merging additional changes from Snikket
Matthew Wild <mwild1@gmail.com>
parents:
4027
diff
changeset
|
183 |
if inviter_username then |
6cdbca89b8be
mod_easy_invite: Minor refactoring to begin merging additional changes from Snikket
Matthew Wild <mwild1@gmail.com>
parents:
4027
diff
changeset
|
184 |
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:
4027
diff
changeset
|
185 |
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:
4027
diff
changeset
|
186 |
end |
3781
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 |
|
4088
9d11c18d4d7e
mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4087
diff
changeset
|
188 |
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:
4087
diff
changeset
|
189 |
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:
4087
diff
changeset
|
190 |
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:
4087
diff
changeset
|
191 |
if roles then |
9d11c18d4d7e
mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4087
diff
changeset
|
192 |
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:
4087
diff
changeset
|
193 |
end |
9d11c18d4d7e
mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4087
diff
changeset
|
194 |
end |
9d11c18d4d7e
mod_easy_invite: Allow setting account roles from associated invite (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4087
diff
changeset
|
195 |
end); |
3781
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 |
|
4089
fe75cc43dfbf
mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents:
4088
diff
changeset
|
197 |
-- 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:
4088
diff
changeset
|
198 |
-- (i.e. password reset) |
fe75cc43dfbf
mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents:
4088
diff
changeset
|
199 |
module:hook("user-password-reset", function (event) |
fe75cc43dfbf
mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents:
4088
diff
changeset
|
200 |
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:
4088
diff
changeset
|
201 |
if not validated_invite then |
fe75cc43dfbf
mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents:
4088
diff
changeset
|
202 |
return; |
fe75cc43dfbf
mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents:
4088
diff
changeset
|
203 |
end |
fe75cc43dfbf
mod_easy_invite: Allow account reset invites
Matthew Wild <mwild1@gmail.com>
parents:
4088
diff
changeset
|
204 |
validated_invite:use(); |
3781
26559776a87e
mod_easy_invite: New module that implements XEP-0401/XEP-0379
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 |
end); |
3782
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
206 |
|
4026
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
207 |
do |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
208 |
-- Telnet command |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
209 |
-- 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:
3792
diff
changeset
|
210 |
-- 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:
3792
diff
changeset
|
211 |
|
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
212 |
local get_module = require "core.modulemanager".get_module; |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
213 |
|
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
214 |
local console_env = module:shared("/*/admin_telnet/env"); |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
215 |
|
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
216 |
-- luacheck: ignore 212/self |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
217 |
console_env.invite = {}; |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
218 |
function console_env.invite:create_account(user_jid) |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
219 |
local username, host = jid_split(user_jid); |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
220 |
local mod_invites, err = get_module(host, "invites"); |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
221 |
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:
3792
diff
changeset
|
222 |
local invite, err = mod_invites.create_account(username); |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
223 |
if not invite then return nil, err; end |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
224 |
return true, invite.uri; |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
225 |
end |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
226 |
|
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
227 |
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:
3792
diff
changeset
|
228 |
local username, host = jid_split(user_jid); |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
229 |
local mod_invites, err = get_module(host, "invites"); |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
230 |
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:
3792
diff
changeset
|
231 |
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:
3792
diff
changeset
|
232 |
if not invite then return nil, err; end |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
233 |
return true, invite.uri; |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
234 |
end |
3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Kim Alvefur <zash@zash.se>
parents:
3792
diff
changeset
|
235 |
end |
3782
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
236 |
|
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
237 |
local sm = require "core.storagemanager"; |
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
238 |
function module.command(arg) |
3792
14028430638b
mod_easy_invite: Change command name to 'generate' (from 'register')
Matthew Wild <mwild1@gmail.com>
parents:
3782
diff
changeset
|
239 |
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:
3782
diff
changeset
|
240 |
print("usage: prosodyctl mod_easy_invite example.net generate"); |
3782
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
241 |
return; |
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
242 |
end |
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
243 |
|
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
244 |
local host = arg[1]; |
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
245 |
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:
3781
diff
changeset
|
246 |
sm.initialize_host(host); |
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
247 |
|
4087
e7eb46d976ae
mod_easy_invite: Add code comment (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4086
diff
changeset
|
248 |
-- Load mod_invites |
3782
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
249 |
invites = module:context(host):depends("invites"); |
4090
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
250 |
module:context(host):depends("invites_page"); |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
251 |
|
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
252 |
table.remove(arg, 1); |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
253 |
table.remove(arg, 1); |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
254 |
|
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
255 |
local invite, roles; |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
256 |
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:
4089
diff
changeset
|
257 |
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:
4089
diff
changeset
|
258 |
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:
4089
diff
changeset
|
259 |
if not username then |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
260 |
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:
4089
diff
changeset
|
261 |
return; |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
262 |
end |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
263 |
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:
4089
diff
changeset
|
264 |
else |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
265 |
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:
4089
diff
changeset
|
266 |
roles = { ["prosody:admin"] = true }; |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
267 |
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:
4089
diff
changeset
|
268 |
roles = { [arg[2]] = true }; |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
269 |
end |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
270 |
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:
4089
diff
changeset
|
271 |
end |
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
272 |
|
50644402c6f5
mod_easy_invite: Rewrite prosodyctl command handler to support new features (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4089
diff
changeset
|
273 |
print(invite.landing_page or invite.uri); |
3782
7209f481bcfe
mod_easy_invite: Add prosodyctl command to generate account invites
Matthew Wild <mwild1@gmail.com>
parents:
3781
diff
changeset
|
274 |
end |