Abstract updating user informations.

main
absc 2024-08-15 21:59:35 +00:00
parent bbb44f9337
commit 812b182499
2 changed files with 31 additions and 5 deletions

View File

@ -26,7 +26,8 @@ from the dudeswave database.
-export([authenticate/2, details/1, new/3, -export([authenticate/2, details/1, new/3,
update/4, delete/1, logout/2, auth_cookies/1, invalidate_cookies/1, 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 """ -doc """
Verify a session with an existing cookie. Verify a session with an existing cookie.
@ -375,3 +376,31 @@ read_new_user_data(Req) ->
<<"email">> := Email} = json:decode(Data), <<"email">> := Email} = json:decode(Data),
{User, Pass, Email, Req0}. {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}.

View File

@ -225,10 +225,7 @@ create_user(Req, State) ->
modify_user(Req, State) -> modify_user(Req, State) ->
{User, _} = dudeswave_auth:auth_cookies(Req), {User, _} = dudeswave_auth:auth_cookies(Req),
{Email, Desc, Name, Req0} = dudeswave_auth:read_update_user_data(Req),
{ok, Data, Req0} = cowboy_req:read_body(Req),
#{<<"email">> := Email, <<"description">> := Desc,
<<"name">> := Name} = json:decode(Data),
case dudeswave_auth:update(User, Name, Email, Desc) of case dudeswave_auth:update(User, Name, Email, Desc) of
ok -> {true, Req0, []}; ok -> {true, Req0, []};