Mercurial > prosody-modules
annotate mod_invites_register/mod_invites_register.lua @ 5186:fa3059e653fa
mod_http_oauth2: Implement the Implicit flow
Everyone says this is insecure and bad, but it's also the only thing
that makes sense for e.g. pure JavaScript clients, but hey implement
this even more complicated thing instead!
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 02 Mar 2023 22:06:50 +0100 |
parents | 4aecf78cc39d |
children |
rev | line source |
---|---|
4106
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local st = require "util.stanza"; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid_split = require "util.jid".split; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local jid_bare = require "util.jid".bare; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local rostermanager = require "core.rostermanager"; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local require_encryption = module:get_option_boolean("c2s_require_encryption", |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 module:get_option_boolean("require_encryption", false)); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local invite_only = module:get_option_boolean("registration_invite_only", true); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local invites; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 if prosody.shutdown then -- COMPAT hack to detect prosodyctl |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 invites = module:depends("invites"); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
4673
eee7ef8eb0a2
mod_invites_register: advertise new stream feature from XEP-0445
Matthew Wild <mwild1@gmail.com>
parents:
4599
diff
changeset
|
15 local legacy_invite_stream_feature = st.stanza("register", { xmlns = "urn:xmpp:invite" }):up(); |
eee7ef8eb0a2
mod_invites_register: advertise new stream feature from XEP-0445
Matthew Wild <mwild1@gmail.com>
parents:
4599
diff
changeset
|
16 local invite_stream_feature = st.stanza("register", { xmlns = "urn:xmpp:ibr-token:0" }):up(); |
4106
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 module:hook("stream-features", function(event) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local session, features = event.origin, event.features; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 -- Advertise to unauthorized clients only. |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 if session.type ~= "c2s_unauthed" or (require_encryption and not session.secure) then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 return |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
4673
eee7ef8eb0a2
mod_invites_register: advertise new stream feature from XEP-0445
Matthew Wild <mwild1@gmail.com>
parents:
4599
diff
changeset
|
25 features:add_child(legacy_invite_stream_feature); |
4106
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 features:add_child(invite_stream_feature); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 -- XEP-0379: Pre-Authenticated Roster Subscription |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 module:hook("presence/bare", function (event) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local stanza = event.stanza; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 if stanza.attr.type ~= "subscribe" then return end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local preauth = stanza:get_child("preauth", "urn:xmpp:pars:0"); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 if not preauth then return end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local token = preauth.attr.token; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 if not token then return end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local username, host = jid_split(stanza.attr.to); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 local invite, err = invites.get(token, username); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 if not invite then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 module:log("debug", "Got invalid token, error: %s", err); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 local contact = jid_bare(stanza.attr.from); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 module:log("debug", "Approving inbound subscription to %s from %s", username, contact); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 if rostermanager.set_contact_pending_in(username, host, contact, stanza) then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 if rostermanager.subscribed(username, host, contact) then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 invite:use(); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 rostermanager.roster_push(username, host, contact); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 -- Send back a subscription request (goal is mutual subscription) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 if not rostermanager.is_user_subscribed(username, host, contact) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 and not rostermanager.is_contact_pending_out(username, host, contact) then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 module:log("debug", "Sending automatic subscription request to %s from %s", contact, username); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 if rostermanager.set_contact_pending_out(username, host, contact) then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 rostermanager.roster_push(username, host, contact); |
4599
06c9c9ef0a51
mod_invites_register: Fix missing 'from' attribute (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
4401
diff
changeset
|
62 module:send(st.presence({type = "subscribe", from = username.."@"..host, to = contact })); |
4106
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 else |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 module:log("warn", "Failed to set contact pending out for %s", username); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 end, 1); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 -- Client is submitting a preauth token to allow registration |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 module:hook("stanza/iq/urn:xmpp:pars:0:preauth", function(event) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 local preauth = event.stanza.tags[1]; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 local token = preauth.attr.token; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 local validated_invite = invites.get(token); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 if not validated_invite then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 local reply = st.error_reply(event.stanza, "cancel", "forbidden", "The invite token is invalid or expired"); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 event.origin.send(reply); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 return true; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 event.origin.validated_invite = validated_invite; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 local reply = st.reply(event.stanza); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 event.origin.send(reply); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 return true; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 end); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 -- Registration attempt - ensure a valid preauth token has been supplied |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 module:hook("user-registering", function (event) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 if invite_only and not validated_invite then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 event.allowed = false; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 event.reason = "Registration on this server is through invitation only"; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 return; |
4121
ee8e7f5196b4
mod_invites_register: Fix traceback for non-invite registrations
Matthew Wild <mwild1@gmail.com>
parents:
4120
diff
changeset
|
94 elseif not validated_invite then |
ee8e7f5196b4
mod_invites_register: Fix traceback for non-invite registrations
Matthew Wild <mwild1@gmail.com>
parents:
4120
diff
changeset
|
95 -- This registration is not using an invite, but |
ee8e7f5196b4
mod_invites_register: Fix traceback for non-invite registrations
Matthew Wild <mwild1@gmail.com>
parents:
4120
diff
changeset
|
96 -- the server is not in invite-only mode, so nothing |
ee8e7f5196b4
mod_invites_register: Fix traceback for non-invite registrations
Matthew Wild <mwild1@gmail.com>
parents:
4120
diff
changeset
|
97 -- for this module to do... |
ee8e7f5196b4
mod_invites_register: Fix traceback for non-invite registrations
Matthew Wild <mwild1@gmail.com>
parents:
4120
diff
changeset
|
98 return; |
4106
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 end |
4120
d3c7be9e36d9
mod_invites_register: Fix traceback on registration via other module (thanks franck)
Kim Alvefur <zash@zash.se>
parents:
4106
diff
changeset
|
100 if validated_invite and validated_invite.additional_data and validated_invite.additional_data.allow_reset then |
4106
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 event.allow_reset = validated_invite.additional_data.allow_reset; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 end); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 -- Make a *one-way* subscription. User will see when contact is online, |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 -- contact will not see when user is online. |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 function subscribe(host, user_username, contact_username) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 local user_jid = user_username.."@"..host; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 local contact_jid = contact_username.."@"..host; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 -- Update user's roster to say subscription request is pending... |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 rostermanager.set_contact_pending_out(user_username, host, contact_jid); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 -- Update contact's roster to say subscription request is pending... |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 rostermanager.set_contact_pending_in(contact_username, host, user_jid); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 -- Update contact's roster to say subscription request approved... |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 rostermanager.subscribed(contact_username, host, user_jid); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 -- Update user's roster to say subscription request approved... |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 rostermanager.process_inbound_subscription_approval(user_username, host, contact_jid); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 -- Make a mutual subscription between jid1 and jid2. Each JID will see |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 -- when the other one is online. |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 function subscribe_both(host, user1, user2) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 subscribe(host, user1, user2); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 subscribe(host, user2, user1); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 -- Registration successful, if there was a preauth token, mark it as used |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 module:hook("user-registered", function (event) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 if not validated_invite then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 return; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 local inviter_username = validated_invite.inviter; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 local contact_username = event.username; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 validated_invite:use(); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 if inviter_username then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 module:log("debug", "Creating mutual subscription between %s and %s", inviter_username, contact_username); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 subscribe_both(module.host, inviter_username, contact_username); |
4907
4aecf78cc39d
mod_invites_register: Push invitee contact entry to inviter (Thanks gerald)
Kim Alvefur <zash@zash.se>
parents:
4673
diff
changeset
|
140 rostermanager.roster_push(inviter_username, module.host, contact_username.."@"..module.host); |
4106
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 if validated_invite.additional_data then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 module:log("debug", "Importing roles from invite"); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 local roles = validated_invite.additional_data.roles; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 if roles then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 module:open_store("roles"):set(contact_username, roles); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 end); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 -- Equivalent of user-registered but for when the account already existed |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 -- (i.e. password reset) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 module:hook("user-password-reset", function (event) |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 if not validated_invite then |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 return; |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 end |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 validated_invite:use(); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 end); |
d34572047488
mod_invites_register: New module to allow IBR with invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 |