Skip to content

Commit

Permalink
Fix admin resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
Premwoik committed Jan 18, 2022
1 parent 9fac90e commit 19a7f36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ execute(_Ctx, _Obj, <<"banUser">>, Args) ->
execute(_Ctx, _Obj, <<"changeUserPassword">>, Args) ->
change_user_password(Args).

register_user(#{<<"domain">> := Server, <<"username">> := Username,
<<"password">> := Password}) ->
Result = mongoose_account_api:register_user(Server, Username, Password),
format_result(Result, #{});
register_user(#{<<"domain">> := Host, <<"password">> := Password}) ->
case mongoose_account_api:register_generated_user(Host, Password) of
{ok, Msg} -> {ok, Msg};
{ErrCode, Msg} -> {error, #{what => ErrCode, msg => Msg}}
end;
register_user(#{<<"domain">> := Server, <<"username">> := Username,
<<"password">> := Password}) ->
Result = mongoose_account_api:register_user(Server, Username, Password),
format_result(Result, #{}).
end.

remove_user(#{<<"user">> := JID}) ->
Result = mongoose_account_api:unregister_user(JID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ check_password(#{<<"user">> := JID, <<"password">> := Password}) ->
{ok, #{<<"correct">> => true, <<"message">> => Msg}}
end.

check_password_hash(#{<<"user">> := JID, <<"password">> := Password,
<<"hashMethod">> := hashMethod}) ->
case mongoose_account_api:check_password(JID, Password) of
check_password_hash(#{<<"user">> := JID, <<"passwordHash">> := Hash,
<<"hashMethod">> := HashMethod}) ->
Val = binary_to_list(Hash),
Method = binary_to_list(HashMethod),
case mongoose_account_api:check_password_hash(JID, Val, Method) of
{error, Msg} ->
{error, #resolver_error{reason = undefined_hash, msg = Msg, context = #{jid => JID}}};
{incorrect, Msg} ->
Expand All @@ -57,7 +59,7 @@ check_password_hash(#{<<"user">> := JID, <<"password">> := Password,
check_user(#{<<"user">> := JID}) ->
case mongoose_account_api:check_account(JID) of
{ok, Msg} ->
{ok, #{exist => true, <<"message">> => Msg}};
{ok, #{<<"exist">> => true, <<"message">> => Msg}};
{user_does_not_exist, Msg} ->
{ok, #{<<"exist">> => false, <<"message">> => Msg}}
end.

0 comments on commit 19a7f36

Please sign in to comment.