powerdns-admin/powerdnsadmin/services/token.py

20 lines
651 B
Python
Raw Normal View History

2019-12-21 14:43:03 +00:00
from flask import current_app
from itsdangerous import URLSafeTimedSerializer
def generate_confirmation_token(email):
serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
return serializer.dumps(email, salt=current_app.config['SALT'])
def confirm_token(token, expiration=86400):
serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
try:
email = serializer.loads(token,
salt=current_app.config['SALT'],
max_age=expiration)
2019-12-21 15:26:56 +00:00
except Exception as e:
current_app.logger.debug(e)
2019-12-21 14:43:03 +00:00
return False
return email