Рефакторинг обработчиков. Часть 1 #21
This commit is contained in:
@@ -3,10 +3,9 @@
|
||||
|
||||
-export([create/2, get_by_id/1, get_by_email/1, update/2, update_status/3, delete/1, update_last_login/1]).
|
||||
-export([email_exists/1]).
|
||||
-export([generate_id/0]).
|
||||
-export([list_users/0]).
|
||||
-export([block/2, unblock/2]).
|
||||
-export([count_users/0, count_users_by_date/2]).
|
||||
-export([count_users/0, count_users_by_date/2, list_all/0]).
|
||||
-export([create_bot/2, delete_bot/1]).
|
||||
|
||||
%% Создание пользователя
|
||||
@@ -16,7 +15,7 @@ create(Email, Password) ->
|
||||
true ->
|
||||
{error, email_exists};
|
||||
false ->
|
||||
Id = generate_id(),
|
||||
Id = infra_utils:generate_id(16),
|
||||
{ok, PasswordHash} = logic_auth:hash_password(Password),
|
||||
|
||||
User = #user{
|
||||
@@ -150,6 +149,10 @@ unblock(Id, Reason) ->
|
||||
count_users() ->
|
||||
mnesia:table_info(user, size).
|
||||
|
||||
%% Административный список (все пользователи, без фильтрации)
|
||||
list_all() ->
|
||||
mnesia:dirty_match_object(#user{_ = '_'}).
|
||||
|
||||
count_users_by_date(From, To) ->
|
||||
All = mnesia:dirty_match_object(#user{_ = '_'}),
|
||||
Filtered = lists:filter(fun(U) ->
|
||||
@@ -166,10 +169,6 @@ count_users_by_date(From, To) ->
|
||||
|
||||
date_part({{Y,M,D}, _}) -> {Y,M,D}.
|
||||
|
||||
%% Внутренние функции
|
||||
generate_id() ->
|
||||
base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}).
|
||||
|
||||
apply_updates(User, Updates) ->
|
||||
Updated = lists:foldl(fun({Field, Value}, U) ->
|
||||
set_field(Field, Value, U)
|
||||
@@ -196,7 +195,7 @@ create_bot(Email, Password) ->
|
||||
case mnesia:dirty_index_read(user, Email, email) of
|
||||
[] ->
|
||||
{ok, PasswordHash} = logic_auth:hash_password(Password),
|
||||
Id = generate_id(),
|
||||
Id = infra_utils:generate_id(16),
|
||||
User = #user{
|
||||
id = Id,
|
||||
email = Email,
|
||||
|
||||
Reference in New Issue
Block a user