Skip to content

Commit 295dfa2

Browse files
committed
Added reset token check route
1 parent acbced4 commit 295dfa2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,20 @@ def reset_password():
9797
u.save()
9898
current_app.logger.debug("/auth/password/reset -> Password reset successfully")
9999
return Success("Password reset successful.")
100+
101+
102+
@auth_password_bp.route("/auth/password/check_token", methods=["POST"])
103+
@validate_params({"token": str})
104+
def check_token_validity():
105+
data = request.get_json()
106+
try:
107+
confirm_token(data["token"], expiration=7200)
108+
except (SignatureExpired, BadSignature) as e:
109+
if e == SignatureExpired:
110+
current_app.logger.debug("/auth/password/reset -> Signature Expired")
111+
raise BadRequestError("Signature Expired.", "Request another password reset and try again.")
112+
else:
113+
current_app.logger.debug("/auth/password/reset -> Bad Signature")
114+
raise BadRequestError("Bad Signature.", "Request another password reset and try again.")
115+
else:
116+
return Success("Reset token is correct")

backend/schemas/swagger.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,43 @@ paths:
959959
message:
960960
type: string
961961
example: Password reset successful.
962+
/auth/password/check_token:
963+
post:
964+
summary: Check the token validity
965+
operationId: checkToken
966+
tags:
967+
- Authentication
968+
requestBody:
969+
description: Parameters to test the token
970+
required: true
971+
content:
972+
application/json:
973+
schema:
974+
type: object
975+
properties:
976+
token:
977+
type: string
978+
required: true
979+
example: qwERg3rtyhog23mrweof5ngib4j3ktnrvwefqjskldnakms
980+
responses:
981+
"400":
982+
$ref: '#/components/responses/BadRequest'
983+
"200":
984+
description: Success
985+
content:
986+
application/json:
987+
schema:
988+
type: object
989+
properties:
990+
code:
991+
type: string
992+
example: 200
993+
success:
994+
type: boolean
995+
example: true
996+
message:
997+
type: string
998+
example: Reset token is correct.
962999

9631000

9641001
servers:

0 commit comments

Comments
 (0)