-
-
Save pcustic/7cf65897eed8177aad11d30d49b8b629 to your computer and use it in GitHub Desktop.
add to app/models.py
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
class User(UserMixin, db.Model): | |
... | |
@staticmethod | |
def validate_reset_password_token(token: str, user_id: int): | |
user = db.session.get(User, user_id) | |
if user is None: | |
return None | |
serializer = URLSafeTimedSerializer(current_app.config["SECRET_KEY"]) | |
try: | |
token_user_email = serializer.loads( | |
token, | |
max_age=current_app.config["RESET_PASS_TOKEN_MAX_AGE"], | |
salt=user.password_hash, | |
) | |
except (BadSignature, SignatureExpired): | |
return None | |
if token_user_email != user.email: | |
return None | |
return user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment