Сделано подтверждение регистрации пользователей #22
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
-module(admin_handler_user_verification_token).
|
||||
-behaviour(cowboy_handler).
|
||||
-export([init/2]).
|
||||
-export([trails/0]).
|
||||
|
||||
init(Req, _Opts) ->
|
||||
case cowboy_req:method(Req) of
|
||||
<<"GET">> -> get_token(Req);
|
||||
_ -> handler_utils:send_error(Req, 405, <<"Method not allowed">>)
|
||||
end.
|
||||
|
||||
get_token(Req) ->
|
||||
case handler_utils:auth_admin(Req) of
|
||||
{ok, _AdminId, Req1} ->
|
||||
UserId = cowboy_req:binding(id, Req1),
|
||||
case core_verification:get_or_create_token(UserId) of
|
||||
{ok, Token, ExpiresAt} ->
|
||||
handler_utils:send_json(Req1, 200, #{
|
||||
<<"token">> => Token,
|
||||
<<"expires_at">> => handler_utils:datetime_to_iso8601(ExpiresAt)
|
||||
});
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req1, 404, <<"User not found">>)
|
||||
end;
|
||||
{error, Code, Msg, Req1} ->
|
||||
handler_utils:send_error(Req1, Code, Msg)
|
||||
end.
|
||||
|
||||
trails() ->
|
||||
[#{path => <<"/v1/admin/users/:id/verification-token">>,
|
||||
method => <<"GET">>,
|
||||
description => <<"Get or create verification token for user (admin)">>,
|
||||
tags => [<<"Users">>],
|
||||
parameters => [#{name => <<"id">>, in => <<"path">>, required => true, schema => #{type => string}}],
|
||||
responses => #{200 => #{description => <<"Token">>}}}].
|
||||
Reference in New Issue
Block a user