Just use the classic POST form.

JSON doesn't make any sense in this case.
main
absc 2024-07-27 12:36:14 +02:00
parent 895e0a5330
commit 80af46c6be
1 changed files with 4 additions and 7 deletions

View File

@ -13,7 +13,7 @@
% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF % ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. % OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
% %
-module(dudeswave_register_handler). -module(dudeswave_user_handler).
-moduledoc """ -moduledoc """
Register a new user. Register a new user.
""". """.
@ -53,17 +53,14 @@ known_methods(Req, State) ->
resource_exists(Req, State) -> resource_exists(Req, State) ->
{ok, Bucket} = maps:find(bucket, State), {ok, Bucket} = maps:find(bucket, State),
case cowboy:read_body(Req, #{period => 5000, length => 8192}) of case cowboy:read_urlencoded_body(Req) of
{ok, Body, NewReq} -> {ok, [{name, Name}, {username, User}, {password, Password}], NewReq} ->
#{<<"name">> := Name, <<"password">> := Pass,
<<"user">> := User} = json:decode(Body),
case storage:read(Bucket, User) of case storage:read(Bucket, User) of
{ok, [_R]} -> {ok, [_R]} ->
{true, NewReq, user_exists}; {true, NewReq, user_exists};
{ok, []} -> {ok, []} ->
{false, NewReq, {Bucket, [{name, Name}, {false, NewReq, {Bucket, [{name, Name},
{username, User},{password, Pass}]}} {username, User},{password, Password}]}}
end end
end. end.