summaryrefslogtreecommitdiff
path: root/sw/auth.py
diff options
context:
space:
mode:
Diffstat (limited to 'sw/auth.py')
-rw-r--r--sw/auth.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/sw/auth.py b/sw/auth.py
index 85212ec..4fd0f68 100644
--- a/sw/auth.py
+++ b/sw/auth.py
@@ -57,14 +57,8 @@ def register():
data = request.json
- if "username" not in data:
- return "Username required", 400
-
- if "password" not in data:
- return "Password required", 400
-
- username = data["username"]
- password = data["password"]
+ username = data.get("username")
+ password = data.get("password")
if username is None:
return "Username required", 400
@@ -99,17 +93,15 @@ def register():
@bp.route("/login", methods=["POST"])
+@json_input
def login():
- if not request.is_json:
- return "Request body is not JSON", 422
-
username = request.json["username"]
password = request.json["password"]
db = get_db()
user = db.execute("select * from users where username=?", (username,)).fetchone()
- if user is None:
+ if (user is None) or (password is None):
return "Username or password incorrect", 403
if not check_password_hash(user["password"], password):