-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokens.py
More file actions
22 lines (18 loc) · 764 Bytes
/
tokens.py
File metadata and controls
22 lines (18 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadSignature
from app 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): # 15 # 3600
serializer = URLSafeTimedSerializer(app.config['SECRET_KEY'])
try:
email = serializer.loads(
token,
salt=app.config['SECURITY_PASSWORD_SALT'],
max_age=expiration
)
except SignatureExpired:
raise Exception('Token has expired')
except BadSignature:
raise Exception('Invalid token') # Raise exception when token is invalid
return email