view mod_block_registrations/mod_block_registrations.lua @ 4709:679f1834dbdb

mod_delegation: update to XEP-0355 v0.5 - namespace bump to "urn:xmpp:delegation:2" - disco remaining infos now uses the XEP defined "urn:xmpp:delegation:2:bare:disco#info:*" namespace - complemeted disco remaining infos implementation for requests made on nodes not already managed by the server - bare JID disco items now uses the XEP defined "urn:xmpp:delegation:2:bare:disco#items:*'" namespace
author Goffi <goffi@goffi.org>
date Fri, 15 Oct 2021 15:10:36 +0200
parents 27aa58ed3e2e
children 368bf9b06484
line wrap: on
line source

local st = require "util.stanza";
local nodeprep = require "util.encodings".stringprep.nodeprep;

local block_users = module:get_option_set("block_registrations_users", { "admin" });
local block_patterns = module:get_option_set("block_registrations_matching", {});
local require_pattern = module:get_option_string("block_registrations_require");

function is_blocked(username)
        -- Check if the username is simply blocked
        if block_users:contains(username) then return true; end

        for pattern in block_patterns do
                if username:find(pattern) then
                        return true;
                end
        end
        -- Not blocked, but check that username matches allowed pattern
        if require_pattern and not username:match(require_pattern) then
                return true;
        end
end

module:hook("user-registering", function(event)
        local username = event.username;
        if is_blocked(username) then
                event.allowed = false;
                return true;
        end
end, 10);