Created
May 23, 2016 19:13
-
-
Save seanbehan/ea919e17a30d7f3195fa15593aa81daf to your computer and use it in GitHub Desktop.
generate signed token for email confirmation with python and flask
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
from itsdangerous import URLSafeTimedSerializer | |
from project import app | |
def generate_confirmation_token(email): | |
serializer = URLSafeTimedSerializer(app.config['SECRET_KEY']) | |
return serializer.dumps(email, salt=app.config['SECURITY_PASSWORD_SALT']) | |
def confirm_token(token, expiration=3600): | |
serializer = URLSafeTimedSerializer(app.config['SECRET_KEY']) | |
try: | |
email = serializer.loads( | |
token, | |
salt=app.config['SECURITY_PASSWORD_SALT'], | |
max_age=expiration | |
) | |
except: | |
return False | |
return email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://realpython.com/blog/python/handling-email-confirmation-in-flask/