From 1019a438325598d2ef51a32250c8082e3dcfc874 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Wed, 12 May 2021 17:32:37 +0200 Subject: [PATCH] Resolve issues #103 and #225 --- .../nest_backend/routes/repository/repositories.py | 2 +- code/backend/nest_backend/routes/users/users.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/code/backend/nest_backend/routes/repository/repositories.py b/code/backend/nest_backend/routes/repository/repositories.py index 0f40f4a..de4ded7 100644 --- a/code/backend/nest_backend/routes/repository/repositories.py +++ b/code/backend/nest_backend/routes/repository/repositories.py @@ -17,7 +17,7 @@ def page_repositories(): - jwt: [] responses: '200': - description: The list of the repositories related to the user (divided in "owner" and "spectator" dict keys), incapsulated in Success. + description: The list of the repositories related to the user, incapsulated in Success. '403': description: The user is not authorized. content: diff --git a/code/backend/nest_backend/routes/users/users.py b/code/backend/nest_backend/routes/users/users.py index 04a83ad..b90e86c 100644 --- a/code/backend/nest_backend/routes/users/users.py +++ b/code/backend/nest_backend/routes/users/users.py @@ -49,6 +49,11 @@ def page_users(): content: application/json: schema: Error + '406': + description: The user already exists. + content: + application/json: + schema: Error '401': description: The user is not logged in. content: @@ -66,8 +71,11 @@ def page_users(): if request.method == "POST": if not user.isAdmin: return json_error("User is not admin. Thou art not authorized."), 403 + if not request.json.get("email") or request.json.get("password") or request.json.get("username"): + return json_error("Missing required fields."), 400 + if User.query.filter_by(email=request.json.get("email")).first(): + return json_error("User already exists."), 406 new_user = User(email=request.json.get("email"), password=gen_password(request.json.get("password")), username=request.json.get("username")) ext.session.add(new_user) - ext.session.commit() return json_success(new_user.to_json()), 201