annotate mod_invites_register/mod_invites_register.lua @ 6257:fa45ae704b79

mod_cloud_notify: Update Readme diff --git a/mod_cloud_notify/README.md b/mod_cloud_notify/README.md --- a/mod_cloud_notify/README.md +++ b/mod_cloud_notify/README.md @@ -1,109 +1,106 @@ ---- -labels: -- 'Stage-Beta' -summary: 'XEP-0357: Cloud push notifications' ---- +# Introduction -Introduction -============ +This module enables support for sending "push notifications" to clients +that need it, typically those running on certain mobile devices. -This module enables support for sending "push notifications" to clients that -need it, typically those running on certain mobile devices. +As well as this module, your client must support push notifications (the +apps that need it generally do, of course) and the app developer's push +gateway must be reachable from your Prosody server (this happens over a +normal XMPP server-to-server 's2s' connection). -As well as this module, your client must support push notifications (the apps -that need it generally do, of course) and the app developer's push gateway -must be reachable from your Prosody server (this happens over a normal XMPP -server-to-server 's2s' connection). - -Details -======= +# Details Some platforms, notably Apple's iOS and many versions of Android, impose -limits that prevent applications from running or accessing the network in the -background. This makes it difficult or impossible for an XMPP application to -remain reliably connected to a server to receive messages. - -In order for messaging and other apps to receive notifications, the OS vendors -run proprietary servers that their OS maintains a permanent connection to in -the background. Then they provide APIs to application developers that allow -sending notifications to specific devices via those servers. +limits that prevent applications from running or accessing the network +in the background. This makes it difficult or impossible for an XMPP +application to remain reliably connected to a server to receive +messages. -When you connect to your server with an app that requires push notifications, -it will use this module to set up a "push registration". When you receive -a message but your device is not connected to the server, this module will -generate a notification and send it to the push gateway operated by your -application's developers). Their gateway will then connect to your device's -OS vendor and ask them to forward the notification to your device. When your -device receives the notification, it will display it or wake up the app so it -can connect to XMPP and receive any pending messages. +In order for messaging and other apps to receive notifications, the OS +vendors run proprietary servers that their OS maintains a permanent +connection to in the background. Then they provide APIs to application +developers that allow sending notifications to specific devices via +those servers. -This protocol is described for developers in [XEP-0357: Push Notifications]. +When you connect to your server with an app that requires push +notifications, it will use this module to set up a "push registration". +When you receive a message but your device is not connected to the +server, this module will generate a notification and send it to the push +gateway operated by your application's developers). Their gateway will +then connect to your device's OS vendor and ask them to forward the +notification to your device. When your device receives the notification, +it will display it or wake up the app so it can connect to XMPP and +receive any pending messages. -For this module to work reliably, you must have [mod_smacks], [mod_mam] and -[mod_carbons] also enabled on your server. +This protocol is described for developers in \[XEP-0357: Push +Notifications\]. + +For this module to work reliably, you must have \[mod_smacks\], +\[mod_mam\] and \[mod_carbons\] also enabled on your server. -Some clients, notably Siskin and Snikket iOS need some additional extensions -that are not currently defined in a standard XEP. To support these clients, -see [mod_cloud_notify_extensions]. +Some clients, notably Siskin and Snikket iOS need some additional +extensions that are not currently defined in a standard XEP. To support +these clients, see \[mod_cloud_notify_extensions\]. -Configuration -============= +# Configuration - Option Default Description - ------------------------------------ ----------------- ------------------------------------------------------------------------------------------------------------------- - `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty - `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled - `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) - `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) - `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. - `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. + Option Default Description + -------------------------------------- ---------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty + `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled + `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) + `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) + `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. + `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. -(\*) There are privacy implications for enabling these options. +(\*) There are privacy implications for enabling these options.[^1] -Internal design notes -===================== +# Internal design notes -App servers are notified about offline messages, messages stored by [mod_mam] -or messages waiting in the smacks queue. -The business rules outlined [here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) are all honored[^2]. +App servers are notified about offline messages, messages stored by +\[mod_mam\] or messages waiting in the smacks queue. The business rules +outlined +[here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) +are all honored[^2]. -To cooperate with [mod_smacks] this module consumes some events: -`smacks-ack-delayed`, `smacks-hibernation-start` and `smacks-hibernation-end`. -These events allow this module to send out notifications for messages received -while the session is hibernated by [mod_smacks] or even when smacks -acknowledgements for messages are delayed by a certain amount of seconds -configurable with the [mod_smacks] setting `smacks_max_ack_delay`. +To cooperate with \[mod_smacks\] this module consumes some events: +`smacks-ack-delayed`, `smacks-hibernation-start` and +`smacks-hibernation-end`. These events allow this module to send out +notifications for messages received while the session is hibernated by +\[mod_smacks\] or even when smacks acknowledgements for messages are +delayed by a certain amount of seconds configurable with the +\[mod_smacks\] setting `smacks_max_ack_delay`. -The `smacks_max_ack_delay` setting allows to send out notifications to clients -which aren't already in smacks hibernation state (because the read timeout or -connection close didn't already happen) but also aren't responding to acknowledgement -request in a timely manner. This setting thus allows conversations to be smoother -under such circumstances. +The `smacks_max_ack_delay` setting allows to send out notifications to +clients which aren't already in smacks hibernation state (because the +read timeout or connection close didn't already happen) but also aren't +responding to acknowledgement request in a timely manner. This setting +thus allows conversations to be smoother under such circumstances. -The new event `cloud-notify-ping` can be used by any module to send out a cloud -notification to either all registered endpoints for the given user or only the endpoints -given in the event data. +The new event `cloud-notify-ping` can be used by any module to send out +a cloud notification to either all registered endpoints for the given +user or only the endpoints given in the event data. -The config setting `push_notification_important_body` can be used to specify an alternative -body text to send to the remote pubsub node if the stanza is encrypted or has a body. -This way the real contents of the message aren't revealed to the push appserver but it -can still see that the push is important. -This is used by Chatsecure on iOS to send out high priority pushes in those cases for example. +The config setting `push_notification_important_body` can be used to +specify an alternative body text to send to the remote pubsub node if +the stanza is encrypted or has a body. This way the real contents of the +message aren't revealed to the push appserver but it can still see that +the push is important. This is used by Chatsecure on iOS to send out +high priority pushes in those cases for example. -Compatibility -============= - -**Note:** This module should be used with Lua 5.2 and higher. Using it with -Lua 5.1 may cause push notifications to not be sent to some clients. +# Compatibility ------- ----------------------------------------------------------------------------- - trunk Works - 0.12 Works - 0.11 Works - 0.10 Works - 0.9 Support dropped, use last supported version [675726ab06d3](//hg.prosody.im/prosody-modules/raw-file/675726ab06d3/mod_cloud_notify/mod_cloud_notify.lua) ------- ----------------------------------------------------------------------------- +**Note:** This module should be used with Lua 5.2 and higher. Using it +with Lua 5.1 may cause push notifications to not be sent to some +clients. + ------- ----------------------------------------------------------------- + trunk Works as of 25-06-13 + 13 Works + 0.12 Works + ------- ----------------------------------------------------------------- -[^1]: The service which is expected to forward notifications to something like Google Cloud Messaging or Apple Notification Service -[^2]: [business_rules.markdown](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.markdown) +[^1]: The service which is expected to forward notifications to + something like Google Cloud Messaging or Apple Notification Service + +[^2]: [business_rules.md](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.md)
author Menel <menel@snikket.de>
date Fri, 13 Jun 2025 10:36:52 +0200
parents 4aecf78cc39d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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