Перенести все админские эндпоинты на порт 8445 и добавить отдельную авторизацию для админов. Часть 2. Final #3
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
-export([email_exists/1]).
|
||||
-export([generate_id/0]).
|
||||
-export([list_users/0]).
|
||||
-export([block/1, unblock/1]).
|
||||
|
||||
%% Создание пользователя
|
||||
create(Email, Password) ->
|
||||
@@ -103,6 +104,24 @@ user_to_map(User) ->
|
||||
updated_at => User#user.updated_at
|
||||
}.
|
||||
|
||||
block(Id) ->
|
||||
case get_by_id(Id) of
|
||||
{ok, User} ->
|
||||
Updated = User#user{status = blocked, updated_at = calendar:universal_time()},
|
||||
mnesia:dirty_write(Updated),
|
||||
{ok, Updated};
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
unblock(Id) ->
|
||||
case get_by_id(Id) of
|
||||
{ok, User} ->
|
||||
Updated = User#user{status = active, updated_at = calendar:universal_time()},
|
||||
mnesia:dirty_write(Updated),
|
||||
{ok, Updated};
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
|
||||
Reference in New Issue
Block a user