Skip to content

Commit 909355b

Browse files
committed
Added already used token in token check
1 parent 18fc29c commit 909355b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

backend/PyMatcha/routes/api/auth/password.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def reset_password():
9999
def check_token_validity():
100100
data = request.get_json()
101101
try:
102-
confirm_token(data["token"], expiration=7200)
102+
email, token_type = confirm_token(data["token"], expiration=7200)
103103
except (SignatureExpired, BadSignature) as e:
104104
if e == SignatureExpired:
105105
current_app.logger.debug("/auth/password/reset -> Signature Expired")
@@ -108,4 +108,12 @@ def check_token_validity():
108108
current_app.logger.debug("/auth/password/reset -> Bad Signature")
109109
raise BadRequestError("Bad Signature.", "Request another password reset and try again.")
110110
else:
111+
try:
112+
u = get_user(email)
113+
except NotFoundError:
114+
current_app.logger.debug("/auth/password/reset -> User not found")
115+
raise NotFoundError("User not found.")
116+
if u.previous_reset_token == data["token"]:
117+
current_app.logger.debug("/auth/password/reset -> Token already used")
118+
raise BadRequestError("Token already used", "Please request a new one.")
111119
return Success("Reset token is correct")

0 commit comments

Comments
 (0)