mirror of
https://github.com/processone/ejabberd.git
synced 2025-01-01 17:53:00 +01:00
Reformat try_set_password/4 function
This commit is contained in:
parent
cbf3fec2c8
commit
fc043dd8cf
@ -273,39 +273,41 @@ try_register_or_set_password(User, Server, Password,
|
|||||||
xmpp:make_error(IQ, xmpp:err_not_allowed())
|
xmpp:make_error(IQ, xmpp:err_not_allowed())
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc Try to change password and return IQ response
|
try_set_password(User, Server, Password) ->
|
||||||
try_set_password(User, Server, Password, #iq{lang = Lang, meta = M} = IQ) ->
|
|
||||||
case is_strong_password(Server, Password) of
|
case is_strong_password(Server, Password) of
|
||||||
true ->
|
true ->
|
||||||
case ejabberd_auth:set_password(User, Server, Password) of
|
ejabberd_auth:set_password(User, Server, Password);
|
||||||
ok ->
|
error_preparing_password ->
|
||||||
?INFO_MSG("~s has changed password from ~s",
|
{error, invalid_password};
|
||||||
[jid:encode({User, Server, <<"">>}),
|
false ->
|
||||||
ejabberd_config:may_hide_data(
|
{error, weak_password}
|
||||||
misc:ip_to_list(maps:get(ip, M, {0,0,0,0})))]),
|
end.
|
||||||
xmpp:make_iq_result(IQ);
|
|
||||||
{error, empty_password} ->
|
try_set_password(User, Server, Password, #iq{lang = Lang, meta = M} = IQ) ->
|
||||||
Txt = <<"Empty password">>,
|
case try_set_password(User, Server, Password) of
|
||||||
xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang));
|
ok ->
|
||||||
{error, not_allowed} ->
|
?INFO_MSG("~s has changed password from ~s",
|
||||||
Txt = <<"Changing password is not allowed">>,
|
[jid:encode({User, Server, <<"">>}),
|
||||||
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
ejabberd_config:may_hide_data(
|
||||||
{error, invalid_jid} ->
|
misc:ip_to_list(maps:get(ip, M, {0,0,0,0})))]),
|
||||||
xmpp:make_error(IQ, xmpp:err_jid_malformed());
|
xmpp:make_iq_result(IQ);
|
||||||
{error, invalid_password} ->
|
{error, not_allowed} ->
|
||||||
Txt = <<"Incorrect password">>,
|
Txt = ?T("Changing password is not allowed"),
|
||||||
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
||||||
Err ->
|
{error, invalid_jid = Why} ->
|
||||||
?ERROR_MSG("failed to register user ~s@~s: ~p",
|
xmpp:make_error(IQ, xmpp:err_jid_malformed(format_error(Why), Lang));
|
||||||
[User, Server, Err]),
|
{error, invalid_password = Why} ->
|
||||||
xmpp:make_error(IQ, xmpp:err_internal_server_error())
|
xmpp:make_error(IQ, xmpp:err_not_allowed(format_error(Why), Lang));
|
||||||
end;
|
{error, weak_password = Why} ->
|
||||||
error_preparing_password ->
|
xmpp:make_error(IQ, xmpp:err_not_acceptable(format_error(Why), Lang));
|
||||||
ErrText = <<"The password contains unacceptable characters">>,
|
{error, empty_password = Why} ->
|
||||||
xmpp:make_error(IQ, xmpp:err_not_acceptable(ErrText, Lang));
|
xmpp:make_error(IQ, xmpp:err_bad_request(format_error(Why), Lang));
|
||||||
false ->
|
{error, db_failure = Why} ->
|
||||||
ErrText = <<"The password is too weak">>,
|
xmpp:make_error(IQ, xmpp:err_internal_server_error(format_error(Why), Lang));
|
||||||
xmpp:make_error(IQ, xmpp:err_not_acceptable(ErrText, Lang))
|
{error, Why} ->
|
||||||
|
?ERROR_MSG("Failed to change password for user ~s@~s: ~s",
|
||||||
|
[User, Server, format_error(Why)]),
|
||||||
|
xmpp:make_error(IQ, xmpp:err_internal_server_error(format_error(Why), Lang))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
try_register(User, Server, Password, SourceRaw) ->
|
try_register(User, Server, Password, SourceRaw) ->
|
||||||
@ -333,7 +335,7 @@ try_register(User, Server, Password, SourceRaw) ->
|
|||||||
false ->
|
false ->
|
||||||
remove_timeout(Source),
|
remove_timeout(Source),
|
||||||
{error, weak_password};
|
{error, weak_password};
|
||||||
_ ->
|
error_preparing_password ->
|
||||||
remove_timeout(Source),
|
remove_timeout(Source),
|
||||||
{error, invalid_password}
|
{error, invalid_password}
|
||||||
end;
|
end;
|
||||||
@ -385,6 +387,8 @@ format_error(weak_password) ->
|
|||||||
?T("The password is too weak");
|
?T("The password is too weak");
|
||||||
format_error(invalid_password) ->
|
format_error(invalid_password) ->
|
||||||
?T("The password contains unacceptable characters");
|
?T("The password contains unacceptable characters");
|
||||||
|
format_error(empty_password) ->
|
||||||
|
?T("Empty password");
|
||||||
format_error(not_allowed) ->
|
format_error(not_allowed) ->
|
||||||
?T("Not allowed");
|
?T("Not allowed");
|
||||||
format_error(exists) ->
|
format_error(exists) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user