Skip to content

Instantly share code, notes, and snippets.

@pcustic
Last active January 16, 2024 15:58
Show Gist options
  • Save pcustic/7cf65897eed8177aad11d30d49b8b629 to your computer and use it in GitHub Desktop.
Save pcustic/7cf65897eed8177aad11d30d49b8b629 to your computer and use it in GitHub Desktop.
add to app/models.py
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