| from flask import current_app |
| from itsdangerous import URLSafeTimedSerializer |
| |
| def generate_token(email): |
| serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY']) |
| return serializer.dumps(email, salt=current_app.config['SECURITY_PASSWORD_SALT']) |
| |
| def confirm_token(token, expiration=86400): |
| serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY']) |
| try: |
| email = serializer.loads( |
| token, |
| salt=current_app.config['SECURITY_PASSWORD_SALT'], |
| max_age=expiration |
| ) |
| return email |
| except: |
| return False |