24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-12 21:52:07 +02:00

Rename is_user_exists -> user_exists

This commit is contained in:
Evgeniy Khramtsov 2017-05-11 15:49:06 +03:00
parent 633b68db11
commit cdb191bb48
15 changed files with 44 additions and 44 deletions

View File

@ -39,7 +39,7 @@
count_users/1, import/5, import_start/2, count_users/1, import/5, import_start/2,
count_users/2, get_password/2, count_users/2, get_password/2,
get_password_s/2, get_password_with_authmodule/2, get_password_s/2, get_password_with_authmodule/2,
is_user_exists/2, is_user_exists_in_other_modules/3, user_exists/2, user_exists_in_other_modules/3,
remove_user/2, remove_user/3, plain_password_required/1, remove_user/2, remove_user/3, plain_password_required/1,
store_type/1, entropy/1, backend_type/1, password_format/1]). store_type/1, entropy/1, backend_type/1, password_format/1]).
%% gen_server callbacks %% gen_server callbacks
@ -73,7 +73,7 @@
-callback store_type(binary()) -> plain | external | scram. -callback store_type(binary()) -> plain | external | scram.
-callback set_password(binary(), binary(), binary()) -> ok | {error, atom()}. -callback set_password(binary(), binary(), binary()) -> ok | {error, atom()}.
-callback remove_user(binary(), binary()) -> ok | {error, any()}. -callback remove_user(binary(), binary()) -> ok | {error, any()}.
-callback is_user_exists(binary(), binary()) -> boolean() | {error, atom()}. -callback user_exists(binary(), binary()) -> boolean() | {error, atom()}.
-callback check_password(binary(), binary(), binary(), binary()) -> boolean(). -callback check_password(binary(), binary(), binary(), binary()) -> boolean().
-callback try_register(binary(), binary(), password()) -> ok | {error, atom()}. -callback try_register(binary(), binary(), password()) -> ok | {error, atom()}.
-callback get_users(binary(), opts()) -> [{binary(), binary()}]. -callback get_users(binary(), opts()) -> [{binary(), binary()}].
@ -84,7 +84,7 @@
-optional_callbacks([set_password/3, -optional_callbacks([set_password/3,
remove_user/2, remove_user/2,
is_user_exists/2, user_exists/2,
check_password/4, check_password/4,
try_register/3, try_register/3,
get_users/2, get_users/2,
@ -250,7 +250,7 @@ set_password(User, Server, Password) ->
try_register(User, Server, Password) -> try_register(User, Server, Password) ->
case validate_credentials(User, Server, Password) of case validate_credentials(User, Server, Password) of
{ok, LUser, LServer} -> {ok, LUser, LServer} ->
case is_user_exists(LUser, LServer) of case user_exists(LUser, LServer) of
true -> true ->
{error, exists}; {error, exists};
false -> false ->
@ -357,15 +357,15 @@ get_password_with_authmodule(User, Server) ->
{false, undefined} {false, undefined}
end. end.
-spec is_user_exists(binary(), binary()) -> boolean(). -spec user_exists(binary(), binary()) -> boolean().
is_user_exists(_User, <<"">>) -> user_exists(_User, <<"">>) ->
false; false;
is_user_exists(User, Server) -> user_exists(User, Server) ->
case validate_credentials(User, Server) of case validate_credentials(User, Server) of
{ok, LUser, LServer} -> {ok, LUser, LServer} ->
lists:any( lists:any(
fun(M) -> fun(M) ->
case db_is_user_exists(LUser, LServer, M) of case db_user_exists(LUser, LServer, M) of
{error, _} -> {error, _} ->
false; false;
Else -> Else ->
@ -376,19 +376,19 @@ is_user_exists(User, Server) ->
false false
end. end.
-spec is_user_exists_in_other_modules(atom(), binary(), binary()) -> boolean() | maybe. -spec user_exists_in_other_modules(atom(), binary(), binary()) -> boolean() | maybe.
is_user_exists_in_other_modules(Module, User, Server) -> user_exists_in_other_modules(Module, User, Server) ->
is_user_exists_in_other_modules_loop( user_exists_in_other_modules_loop(
auth_modules(Server) -- [Module], User, Server). auth_modules(Server) -- [Module], User, Server).
is_user_exists_in_other_modules_loop([], _User, _Server) -> user_exists_in_other_modules_loop([], _User, _Server) ->
false; false;
is_user_exists_in_other_modules_loop([AuthModule | AuthModules], User, Server) -> user_exists_in_other_modules_loop([AuthModule | AuthModules], User, Server) ->
case db_is_user_exists(User, Server, AuthModule) of case db_user_exists(User, Server, AuthModule) of
true -> true ->
true; true;
false -> false ->
is_user_exists_in_other_modules_loop(AuthModules, User, Server); user_exists_in_other_modules_loop(AuthModules, User, Server);
{error, _} -> {error, _} ->
maybe maybe
end. end.
@ -537,14 +537,14 @@ db_get_password(User, Server, Mod) ->
Mod:get_password(User, Server) Mod:get_password(User, Server)
end. end.
db_is_user_exists(User, Server, Mod) -> db_user_exists(User, Server, Mod) ->
case db_get_password(User, Server, Mod) of case db_get_password(User, Server, Mod) of
{ok, _} -> {ok, _} ->
true; true;
error -> error ->
case Mod:store_type(Server) of case Mod:store_type(Server) of
external -> external ->
Mod:is_user_exists(User, Server); Mod:user_exists(User, Server);
_ -> _ ->
false false
end end

View File

@ -40,7 +40,7 @@
unregister_connection/3 unregister_connection/3
]). ]).
-export([login/2, check_password/4, is_user_exists/2, -export([login/2, check_password/4, user_exists/2,
get_users/2, count_users/2, store_type/1, get_users/2, count_users/2, store_type/1,
plain_password_required/1, opt_type/1]). plain_password_required/1, opt_type/1]).
@ -135,7 +135,7 @@ unregister_connection(_SID,
%% --------------------------------- %% ---------------------------------
check_password(User, _AuthzId, Server, _Password) -> check_password(User, _AuthzId, Server, _Password) ->
case case
ejabberd_auth:is_user_exists_in_other_modules(?MODULE, ejabberd_auth:user_exists_in_other_modules(?MODULE,
User, Server) User, Server)
of of
%% If user exists in other module, reject anonnymous authentication %% If user exists in other module, reject anonnymous authentication
@ -165,7 +165,7 @@ get_users(Server, _) ->
count_users(Server, Opts) -> count_users(Server, Opts) ->
length(get_users(Server, Opts)). length(get_users(Server, Opts)).
is_user_exists(User, Server) -> user_exists(User, Server) ->
anonymous_user_exist(User, Server). anonymous_user_exist(User, Server).
plain_password_required(_) -> plain_password_required(_) ->

View File

@ -32,7 +32,7 @@
-behaviour(ejabberd_auth). -behaviour(ejabberd_auth).
-export([start/1, stop/1, set_password/3, check_password/4, -export([start/1, stop/1, set_password/3, check_password/4,
try_register/3, is_user_exists/2, remove_user/2, try_register/3, user_exists/2, remove_user/2,
store_type/1, plain_password_required/1, opt_type/1]). store_type/1, plain_password_required/1, opt_type/1]).
-include("ejabberd.hrl"). -include("ejabberd.hrl").
@ -68,8 +68,8 @@ set_password(User, Server, Password) ->
try_register(User, Server, Password) -> try_register(User, Server, Password) ->
extauth:try_register(User, Server, Password). extauth:try_register(User, Server, Password).
is_user_exists(User, Server) -> user_exists(User, Server) ->
try extauth:is_user_exists(User, Server) of try extauth:user_exists(User, Server) of
Res -> Res Res -> Res
catch catch
_:Error -> _:Error ->

View File

@ -37,7 +37,7 @@
handle_cast/2, terminate/2, code_change/3]). handle_cast/2, terminate/2, code_change/3]).
-export([start/1, stop/1, start_link/1, set_password/3, -export([start/1, stop/1, start_link/1, set_password/3,
check_password/4, is_user_exists/2, check_password/4, user_exists/2,
get_users/2, count_users/2, get_users/2, count_users/2,
store_type/1, plain_password_required/1, store_type/1, plain_password_required/1,
opt_type/1]). opt_type/1]).
@ -147,8 +147,8 @@ count_users(Server, Opts) ->
length(get_users(Server, Opts)). length(get_users(Server, Opts)).
%% @spec (User, Server) -> true | false | {error, Error} %% @spec (User, Server) -> true | false | {error, Error}
is_user_exists(User, Server) -> user_exists(User, Server) ->
case catch is_user_exists_ldap(User, Server) of case catch user_exists_ldap(User, Server) of
{'EXIT', _Error} -> {error, db_failure}; {'EXIT', _Error} -> {error, db_failure};
Result -> Result Result -> Result
end. end.
@ -218,7 +218,7 @@ get_users_ldap(Server) ->
_ -> [] _ -> []
end. end.
is_user_exists_ldap(User, Server) -> user_exists_ldap(User, Server) ->
{ok, State} = eldap_utils:get_state(Server, ?MODULE), {ok, State} = eldap_utils:get_state(Server, ?MODULE),
case find_user_dn(User, State) of case find_user_dn(User, State) of
false -> false; false -> false;

View File

@ -31,7 +31,7 @@
-behaviour(ejabberd_auth). -behaviour(ejabberd_auth).
-export([start/1, stop/1, check_password/4, -export([start/1, stop/1, check_password/4,
is_user_exists/2, store_type/1, plain_password_required/1, user_exists/2, store_type/1, plain_password_required/1,
opt_type/1]). opt_type/1]).
start(_Host) -> start(_Host) ->
@ -57,7 +57,7 @@ check_password(User, AuthzId, Host, Password) ->
end end
end. end.
is_user_exists(User, Host) -> user_exists(User, Host) ->
Service = get_pam_service(Host), Service = get_pam_service(Host),
UserInfo = case get_pam_userinfotype(Host) of UserInfo = case get_pam_userinfotype(Host) of
username -> User; username -> User;

View File

@ -178,7 +178,7 @@ close_session(SID, User, Server, Resource) ->
subscribe | subscribed | unsubscribe | unsubscribed, subscribe | subscribed | unsubscribe | unsubscribed,
binary()) -> boolean() | {stop, false}. binary()) -> boolean() | {stop, false}.
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) -> check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
case ejabberd_auth:is_user_exists(User, Server) of case ejabberd_auth:user_exists(User, Server) of
true -> Acc; true -> Acc;
false -> {stop, false} false -> {stop, false}
end. end.
@ -716,7 +716,7 @@ route_message(#message{to = To, type = Type} = Packet) ->
end, end,
PrioRes); PrioRes);
_ -> _ ->
case ejabberd_auth:is_user_exists(LUser, LServer) andalso case ejabberd_auth:user_exists(LUser, LServer) andalso
is_privacy_allow(Packet) of is_privacy_allow(Packet) of
true -> true ->
ejabberd_hooks:run_fold(offline_message_hook, ejabberd_hooks:run_fold(offline_message_hook,

View File

@ -281,7 +281,7 @@ get_auth_account(HostOfRule, AccessRule, User, Server,
true -> {ok, {User, Server}} true -> {ok, {User, Server}}
end; end;
false -> false ->
case ejabberd_auth:is_user_exists(User, Server) of case ejabberd_auth:user_exists(User, Server) of
true -> {unauthorized, <<"bad-password">>}; true -> {unauthorized, <<"bad-password">>};
false -> {unauthorized, <<"inexistent-account">>} false -> {unauthorized, <<"inexistent-account">>}
end end
@ -1025,7 +1025,7 @@ process_admin(Host,
process_admin(Host, process_admin(Host,
#request{path = [<<"user">>, U], #request{path = [<<"user">>, U],
auth = {_, _Auth, AJID}, q = Query, lang = Lang}) -> auth = {_, _Auth, AJID}, q = Query, lang = Lang}) ->
case ejabberd_auth:is_user_exists(U, Host) of case ejabberd_auth:user_exists(U, Host) of
true -> true ->
Res = user_info(U, Host, Query, Lang), Res = user_info(U, Host, Query, Lang),
make_xhtml(Res, Host, Lang, AJID); make_xhtml(Res, Host, Lang, AJID);

View File

@ -31,7 +31,7 @@
-export([start/2, stop/1, init/2, check_password/3, -export([start/2, stop/1, init/2, check_password/3,
set_password/3, try_register/3, remove_user/2, set_password/3, try_register/3, remove_user/2,
remove_user/3, is_user_exists/2, opt_type/1]). remove_user/3, user_exists/2, opt_type/1]).
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("logger.hrl"). -include("logger.hrl").
@ -73,7 +73,7 @@ get_process_name(Host, Integer) ->
check_password(User, Server, Password) -> check_password(User, Server, Password) ->
call_port(Server, [<<"auth">>, User, Server, Password]). call_port(Server, [<<"auth">>, User, Server, Password]).
is_user_exists(User, Server) -> user_exists(User, Server) ->
call_port(Server, [<<"isuser">>, User, Server]). call_port(Server, [<<"isuser">>, User, Server]).
set_password(User, Server, Password) -> set_password(User, Server, Password) ->

View File

@ -210,7 +210,7 @@ get_commands_spec() ->
result_desc = "Result tuple"}, result_desc = "Result tuple"},
#ejabberd_commands{name = check_account, tags = [accounts], #ejabberd_commands{name = check_account, tags = [accounts],
desc = "Check if an account exists or not", desc = "Check if an account exists or not",
module = ejabberd_auth, function = is_user_exists, module = ejabberd_auth, function = user_exists,
args = [{user, binary}, {host, binary}], args = [{user, binary}, {host, binary}],
args_example = [<<"peter">>, <<"myserver.com">>], args_example = [<<"peter">>, <<"myserver.com">>],
args_desc = ["User name to check", "Server to check"], args_desc = ["User name to check", "Server to check"],
@ -1638,7 +1638,7 @@ decide_rip_jid({UName, UServer}, Match_list) ->
Match_list). Match_list).
user_action(User, Server, Fun, OK) -> user_action(User, Server, Fun, OK) ->
case ejabberd_auth:is_user_exists(User, Server) of case ejabberd_auth:user_exists(User, Server) of
true -> true ->
case catch Fun() of case catch Fun() of
OK -> ok; OK -> ok;

View File

@ -1541,7 +1541,7 @@ set_form(From, Host, ?NS_ADMINL(<<"delete-user">>),
Server = JID#jid.lserver, Server = JID#jid.lserver,
true = Server == Host orelse true = Server == Host orelse
get_permission_level(From) == global, get_permission_level(From) == global,
true = ejabberd_auth:is_user_exists(User, Server), true = ejabberd_auth:user_exists(User, Server),
{User, Server} {User, Server}
end, end,
AccountStringList), AccountStringList),
@ -1610,7 +1610,7 @@ set_form(From, Host,
Server = JID#jid.lserver, Server = JID#jid.lserver,
true = Server == Host orelse true = Server == Host orelse
get_permission_level(From) == global, get_permission_level(From) == global,
true = ejabberd_auth:is_user_exists(User, Server), true = ejabberd_auth:user_exists(User, Server),
ejabberd_auth:set_password(User, Server, Password), ejabberd_auth:set_password(User, Server, Password),
{result, undefined}; {result, undefined};
set_form(From, Host, set_form(From, Host,

View File

@ -376,7 +376,7 @@ process_sm_iq_info(#iq{type = get, lang = Lang,
get_sm_identity(Acc, _From, get_sm_identity(Acc, _From,
#jid{luser = LUser, lserver = LServer}, _Node, _Lang) -> #jid{luser = LUser, lserver = LServer}, _Node, _Lang) ->
Acc ++ Acc ++
case ejabberd_auth:is_user_exists(LUser, LServer) of case ejabberd_auth:user_exists(LUser, LServer) of
true -> true ->
[#identity{category = <<"account">>, type = <<"registered">>}]; [#identity{category = <<"account">>, type = <<"registered">>}];
_ -> [] _ -> []

View File

@ -198,7 +198,7 @@ process_iq(#iq{type = get, from = From, to = To, id = ID, lang = Lang} = IQ,
{IsRegistered, Username} = {IsRegistered, Username} =
case From of case From of
#jid{user = User, lserver = Server} -> #jid{user = User, lserver = Server} ->
case ejabberd_auth:is_user_exists(User, Server) of case ejabberd_auth:user_exists(User, Server) of
true -> true ->
{true, User}; {true, User};
false -> false ->

View File

@ -438,7 +438,7 @@ change_password(Username, Host, PasswordOld,
end. end.
check_account_exists(Username, Host) -> check_account_exists(Username, Host) ->
case ejabberd_auth:is_user_exists(Username, Host) of case ejabberd_auth:user_exists(Username, Host) of
true -> account_exists; true -> account_exists;
false -> account_doesnt_exist false -> account_doesnt_exist
end. end.

View File

@ -390,7 +390,7 @@ search_group_info(State, Group) ->
end end
end, end,
AuthChecker = case State#state.auth_check of AuthChecker = case State#state.auth_check of
true -> fun ejabberd_auth:is_user_exists/2; true -> fun ejabberd_auth:user_exists/2;
_ -> fun (_U, _S) -> true end _ -> fun (_U, _S) -> true end
end, end,
case eldap_search(State, case eldap_search(State,

View File

@ -148,7 +148,7 @@ search_items(Entries, State) ->
{U, UIDAttrFormat} -> {U, UIDAttrFormat} ->
case eldap_utils:get_user_part(U, UIDAttrFormat) of case eldap_utils:get_user_part(U, UIDAttrFormat) of
{ok, Username} -> {ok, Username} ->
case ejabberd_auth:is_user_exists(Username, case ejabberd_auth:user_exists(Username,
LServer) of LServer) of
true -> true ->
RFields = lists:map( RFields = lists:map(