25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Add support to provide ban detail when account logins (#4201)

This commit is contained in:
Badlop 2024-04-24 21:02:31 +02:00
parent 2bfc4b0f5d
commit 94a0aa6967

View File

@ -236,14 +236,16 @@ check_password_with_authmodule(User, AuthzId, Server, Password) ->
-spec check_password_with_authmodule( -spec check_password_with_authmodule(
binary(), binary(), binary(), binary(), binary(), binary(), binary(), binary(), binary(), binary(),
digest_fun() | undefined) -> false | {true, atom()}. digest_fun() | undefined) -> false | {false, atom(), binary()} | {true, atom()}.
check_password_with_authmodule(User, AuthzId, Server, Password, Digest, DigestGen) -> check_password_with_authmodule(User, AuthzId, Server, Password, Digest, DigestGen) ->
case validate_credentials(User, Server) of case validate_credentials(User, Server) of
{ok, LUser, LServer} -> {ok, LUser, LServer} ->
case jid:nodeprep(AuthzId) of case {jid:nodeprep(AuthzId), get_is_banned(LUser, LServer)} of
error -> {error, _} ->
false; false;
LAuthzId -> {_, {is_banned, BanReason}} ->
{false, 'account-disabled', BanReason};
{LAuthzId, _} ->
untag_stop( untag_stop(
lists:foldl( lists:foldl(
fun(Mod, false) -> fun(Mod, false) ->
@ -373,10 +375,15 @@ get_password_s(User, Server) ->
Password -> Password Password -> Password
end. end.
-spec get_password_with_authmodule(binary(), binary()) -> {false | password(), module()}. -spec get_password_with_authmodule(binary(), binary()) ->
{false | {false, atom(), binary()} | password(), module()}.
get_password_with_authmodule(User, Server) -> get_password_with_authmodule(User, Server) ->
case validate_credentials(User, Server) of case validate_credentials(User, Server) of
{ok, LUser, LServer} -> {ok, LUser, LServer} ->
case get_is_banned(LUser, LServer) of
{is_banned, BanReason} ->
{{false, 'account-disabled', BanReason}, module_not_consulted};
not_banned ->
case lists:foldl( case lists:foldl(
fun(M, {error, _}) -> fun(M, {error, _}) ->
{db_get_password(LUser, LServer, M), M}; {db_get_password(LUser, LServer, M), M};
@ -387,6 +394,7 @@ get_password_with_authmodule(User, Server) ->
{Password, Module}; {Password, Module};
{error, Module} -> {error, Module} ->
{false, Module} {false, Module}
end
end; end;
_ -> _ ->
{false, undefined} {false, undefined}
@ -567,6 +575,15 @@ backend_type(Mod) ->
password_format(LServer) -> password_format(LServer) ->
ejabberd_option:auth_password_format(LServer). ejabberd_option:auth_password_format(LServer).
get_is_banned(User, Server) ->
case mod_admin_extra:get_ban_details(User, Server) of
[] ->
not_banned;
BanDetails ->
{_, ReasonText} = lists:keyfind("reason", 1, BanDetails),
{is_banned, <<"Account is banned: ", ReasonText/binary>>}
end.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% Backend calls %%% Backend calls
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------