Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from Police-Data-Accessibility-Project/improv…
…ed_password_reset Improved password reset
- Loading branch information
Showing
9 changed files
with
152 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from flask_restful import Resource | ||
from flask import request | ||
from middleware.reset_token_queries import ( | ||
check_reset_token, | ||
) | ||
from datetime import datetime as dt | ||
|
||
|
||
class ResetTokenValidation(Resource): | ||
def __init__(self, **kwargs): | ||
self.psycopg2_connection = kwargs["psycopg2_connection"] | ||
|
||
def post(self): | ||
try: | ||
data = request.get_json() | ||
token = data.get("token") | ||
cursor = self.psycopg2_connection.cursor() | ||
token_data = check_reset_token(cursor, token) | ||
if "create_date" not in token_data: | ||
return {"message": "The submitted token is invalid"}, 400 | ||
|
||
token_create_date = token_data["create_date"] | ||
token_expired = (dt.utcnow() - token_create_date).total_seconds() > 900 | ||
|
||
if token_expired: | ||
return {"message": "The submitted token is invalid"}, 400 | ||
|
||
return {"message": "Token is valid"} | ||
|
||
except Exception as e: | ||
self.psycopg2_connection.rollback() | ||
print(str(e)) | ||
return {"message": str(e)}, 500 |