Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Created May 23, 2016 19:13
Show Gist options
  • Save seanbehan/ea919e17a30d7f3195fa15593aa81daf to your computer and use it in GitHub Desktop.
Save seanbehan/ea919e17a30d7f3195fa15593aa81daf to your computer and use it in GitHub Desktop.
generate signed token for email confirmation with python and flask
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
@seanbehan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment