1 |
|
-module(mongoose_graphql_helper). |
2 |
|
-export([check_user/1]). |
3 |
|
|
4 |
|
-include("jlib.hrl"). |
5 |
|
|
6 |
|
-spec check_user(#jid{}) -> {ok, mongooseim:host_type()} | {error, term()}. |
7 |
|
check_user(#jid{lserver = LServer} = Jid) -> |
8 |
:-( |
case mongoose_domain_api:get_domain_host_type(LServer) of |
9 |
|
{ok, HostType} -> |
10 |
:-( |
check_auth(HostType, Jid); |
11 |
|
_ -> |
12 |
:-( |
{error, #{what => unknown_domain, domain => LServer}} |
13 |
|
end. |
14 |
|
|
15 |
|
check_auth(HostType, Jid) -> |
16 |
:-( |
case ejabberd_auth:does_user_exist(HostType, Jid, stored) of |
17 |
|
true -> |
18 |
:-( |
{ok, HostType}; |
19 |
|
false -> |
20 |
:-( |
{error, #{what => unknown_user, jid => jid:to_binary(Jid)}} |
21 |
|
end. |