diff --git a/backend/auth.py b/backend/auth.py index 1f674fb..e0cbd41 100644 --- a/backend/auth.py +++ b/backend/auth.py @@ -153,7 +153,31 @@ def change_password(user_id: int, old_password: str, new_password: str): "status": "updated", } -def delete_me(user_id): +def delete_me(user_id, password): + user = fetch_one( + """ + SELECT password_hash + FROM users + WHERE id = ? + """, + (user_id,) + ) + + if user is None: + return { + "status": "failed", + "reason": "user_not_found", + } + + if not bcrypt.checkpw( + password.encode(), + user["password_hash"].encode(), + ): + return { + "status": "failed", + "reason": "incorrect_password", + } + owned_rooms = fetch_all( """ SELECT id @@ -208,4 +232,6 @@ def delete_me(user_id): (user_id,) ) - return {"status": "deleted"} + return { + "status": "deleted" + }