annotate mod_block_registrations/mod_block_registrations.lua @ 3656:3e0f4d727825

mod_vcard_muc: Add an alternative method of signaling avatar change When the avatar has been changed, a signal is sent that the room configuration has changed. Clients then do a disco#info query to find the SHA-1 of the new avatar. They can then fetch it as before, or not if they have it cached already. This is meant to be less disruptive than signaling via presence, which caused problems for some clients. If clients transition to the new method, the old one can eventually be removed. The namespace is made up while waiting for standardization. Otherwise it is very close to what's described in https://xmpp.org/extensions/inbox/muc-avatars.html
author Kim Alvefur <zash@zash.se>
date Sun, 25 Aug 2019 20:46:43 +0200
parents 27aa58ed3e2e
children 368bf9b06484
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1053
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local st = require "util.stanza";
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local nodeprep = require "util.encodings".stringprep.nodeprep;
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local block_users = module:get_option_set("block_registrations_users", { "admin" });
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local block_patterns = module:get_option_set("block_registrations_matching", {});
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local require_pattern = module:get_option_string("block_registrations_require");
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 function is_blocked(username)
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 -- Check if the username is simply blocked
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 if block_users:contains(username) then return true; end
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 for pattern in block_patterns do
1697
27aa58ed3e2e mod_block_registrations: string.find is faster than string.match when only needing a boolean answer
Kim Alvefur <zash@zash.se>
parents: 1331
diff changeset
13 if username:find(pattern) then
1053
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 return true;
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 end
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 -- Not blocked, but check that username matches allowed pattern
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 if require_pattern and not username:match(require_pattern) then
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 return true;
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22
1331
dbaa67babeb4 mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents: 1053
diff changeset
23 module:hook("user-registering", function(event)
dbaa67babeb4 mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents: 1053
diff changeset
24 local username = event.username;
dbaa67babeb4 mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents: 1053
diff changeset
25 if is_blocked(username) then
dbaa67babeb4 mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents: 1053
diff changeset
26 event.allowed = false;
dbaa67babeb4 mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents: 1053
diff changeset
27 return true;
1053
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end
cabbcc1997d9 mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 end, 10);