mod_muc_restrict_nick/mod_muc_restrict_nick.lua
author Kim Alvefur <zash@zash.se>
Thu, 04 Jul 2024 16:06:32 +0200
changeset 5929 32d1abb89dfe
parent 4592 e7b126161e7b
permissions -rw-r--r--
mod_rest: Reject password that fails saslprep earlier (thanks tgy) Prevents an error later if/when passing the password through saslprep a second time in the authentication module, since the prep functions now reject nil The error reporting could be improved but that would involve adding a way to pass errors back out of the check_credentials() function.

local jid = require "util.jid";
local st = require "util.stanza";

local nick_pattern = module:get_option_string("muc_restrict_nick_pattern", "^%w+$");

module:hook("muc-occupant-pre-join", function (event)
	local nick = jid.resource(event.occupant.nick);
	if not nick:match(nick_pattern) then
		local reply = st.error_reply(event.stanza, "modify", "policy-violation", "Unacceptable nickname, please try another");
		module:send(reply);
		return true;
	end
end);