-callback plain_password_required(binary()) -> boolean().
-callback store_type(binary()) -> plain | external | scram.
-callback set_password(binary(), binary(), password()) ->
- {ets_cache:tag(), {ok, password()} | {error, db_failure}}.
+ {ets_cache:tag(), {ok, password()} | {error, db_failure | not_allowed}}.
-callback remove_user(binary(), binary()) -> ok | {error, db_failure | not_allowed}.
-callback user_exists(binary(), binary()) -> {ets_cache:tag(), boolean() | {error, db_failure}}.
-callback check_password(binary(), binary(), binary(), binary()) -> {ets_cache:tag(), boolean()}.
false
end.
--spec set_password(binary(), binary(), password()) -> ok | {error, atom()}.
+-spec set_password(binary(), binary(), password()) -> ok | {error,
+ db_failure | not_allowed |
+ invalid_jid | invalid_password}.
set_password(User, Server, Password) ->
case validate_credentials(User, Server, Password) of
{ok, LUser, LServer} ->
Err
end.
--spec try_register(binary(), binary(), password()) -> ok | {error, atom()}.
+-spec try_register(binary(), binary(), password()) -> ok | {error,
+ db_failure | not_allowed | exists |
+ invalid_jid | invalid_password}.
try_register(User, Server, Password) ->
case validate_credentials(User, Server, Password) of
{ok, LUser, LServer} ->
%%%----------------------------------------------------------------------
%%% Backend calls
%%%----------------------------------------------------------------------
+-spec db_try_register(binary(), binary(), password(), module()) -> ok | {error, exists | db_failure | not_allowed}.
db_try_register(User, Server, Password, Mod) ->
case erlang:function_exported(Mod, try_register, 3) of
true ->
scram -> password_to_scram(Password);
_ -> Password
end,
- case use_cache(Mod, Server) of
- true ->
- case ets_cache:update(
- cache_tab(Mod), {User, Server}, {ok, Password},
- fun() -> Mod:try_register(User, Server, Password1) end,
- cache_nodes(Mod, Server)) of
- {ok, _} -> ok;
- {error, _} = Err -> Err
- end;
- false ->
- ets_cache:untag(Mod:try_register(User, Server, Password1))
+ Ret = case use_cache(Mod, Server) of
+ true ->
+ ets_cache:update(
+ cache_tab(Mod), {User, Server}, {ok, Password},
+ fun() -> Mod:try_register(User, Server, Password1) end,
+ cache_nodes(Mod, Server));
+ false ->
+ ets_cache:untag(Mod:try_register(User, Server, Password1))
+ end,
+ case Ret of
+ {ok, _} -> ok;
+ {error, _} = Err -> Err
end;
false ->
{error, not_allowed}
end.
+-spec db_set_password(binary(), binary(), password(), module()) -> ok | {error, db_failure | not_allowed}.
db_set_password(User, Server, Password, Mod) ->
case erlang:function_exported(Mod, set_password, 3) of
true ->
scram -> password_to_scram(Password);
_ -> Password
end,
- case use_cache(Mod, Server) of
- true ->
- case ets_cache:update(
- cache_tab(Mod), {User, Server}, {ok, Password},
- fun() -> Mod:set_password(User, Server, Password1) end,
- cache_nodes(Mod, Server)) of
- {ok, _} -> ok;
- {error, _} = Err -> Err
- end;
- false ->
- ets_cache:untag(Mod:set_password(User, Server, Password1))
+ Ret = case use_cache(Mod, Server) of
+ true ->
+ ets_cache:update(
+ cache_tab(Mod), {User, Server}, {ok, Password},
+ fun() -> Mod:set_password(User, Server, Password1) end,
+ cache_nodes(Mod, Server));
+ false ->
+ ets_cache:untag(Mod:set_password(User, Server, Password1))
+ end,
+ case Ret of
+ {ok, _} -> ok;
+ {error, _} = Err -> Err
end;
false ->
{error, not_allowed}
xmpp:make_error(IQ, xmpp:err_not_allowed(format_error(Why), Lang));
{error, weak_password = Why} ->
xmpp:make_error(IQ, xmpp:err_not_acceptable(format_error(Why), Lang));
- {error, empty_password = Why} ->
- xmpp:make_error(IQ, xmpp:err_bad_request(format_error(Why), Lang));
{error, db_failure = Why} ->
- xmpp:make_error(IQ, xmpp:err_internal_server_error(format_error(Why), 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.
{error, exists = Why} ->
{error, xmpp:err_conflict(format_error(Why), Lang)};
{error, db_failure = Why} ->
- {error, xmpp:err_internal_server_error(format_error(Why), Lang)};
- {error, Why} ->
- ?ERROR_MSG("Failed to register user ~s@~s: ~s",
- [User, Server, format_error(Why)]),
{error, xmpp:err_internal_server_error(format_error(Why), Lang)}
end.
?T("The password is too weak");
format_error(invalid_password) ->
?T("The password contains unacceptable characters");
-format_error(empty_password) ->
- ?T("Empty password");
format_error(not_allowed) ->
?T("Not allowed");
format_error(exists) ->