Abstract updating user informations.
parent
bbb44f9337
commit
812b182499
|
@ -26,7 +26,8 @@ from the dudeswave database.
|
|||
|
||||
-export([authenticate/2, details/1, new/3,
|
||||
update/4, delete/1, logout/2, auth_cookies/1, invalidate_cookies/1,
|
||||
set_auth_cookies/4, read_login_data/1, read_new_user_data/1]).
|
||||
set_auth_cookies/4, read_login_data/1, read_new_user_data/1,
|
||||
read_update_user_data/1]).
|
||||
|
||||
-doc """
|
||||
Verify a session with an existing cookie.
|
||||
|
@ -375,3 +376,31 @@ read_new_user_data(Req) ->
|
|||
<<"email">> := Email} = json:decode(Data),
|
||||
|
||||
{User, Pass, Email, Req0}.
|
||||
|
||||
-doc """
|
||||
Update user informations.
|
||||
|
||||
Spec:
|
||||
|
||||
```
|
||||
-spec read_update_user_data(Req) -> {Email, Desc, Name, Req0} when
|
||||
Req :: cowboy_req:req(),
|
||||
Email :: binary(),
|
||||
Desc :: binary(),
|
||||
Name :: binary(),
|
||||
Req0 :: cowboy_req:req().
|
||||
```
|
||||
""".
|
||||
-spec read_update_user_data(Req) -> {Email, Desc, Name, Req0} when
|
||||
Req :: cowboy_req:req(),
|
||||
Email :: binary(),
|
||||
Desc :: binary(),
|
||||
Name :: binary(),
|
||||
Req0 :: cowboy_req:req().
|
||||
|
||||
read_update_user_data(Req) ->
|
||||
{ok, Data, Req0} = cowboy_req:read_body(Req),
|
||||
#{<<"email">> := Email, <<"description">> := Desc,
|
||||
<<"name">> := Name} = json:decode(Data),
|
||||
|
||||
{Email, Desc, Name, Req0}.
|
|
@ -225,10 +225,7 @@ create_user(Req, State) ->
|
|||
|
||||
modify_user(Req, State) ->
|
||||
{User, _} = dudeswave_auth:auth_cookies(Req),
|
||||
|
||||
{ok, Data, Req0} = cowboy_req:read_body(Req),
|
||||
#{<<"email">> := Email, <<"description">> := Desc,
|
||||
<<"name">> := Name} = json:decode(Data),
|
||||
{Email, Desc, Name, Req0} = dudeswave_auth:read_update_user_data(Req),
|
||||
|
||||
case dudeswave_auth:update(User, Name, Email, Desc) of
|
||||
ok -> {true, Req0, []};
|
||||
|
|
Loading…
Reference in New Issue