aboutsummaryrefslogtreecommitdiff
path: root/src/web/lib/user_utils.py
blob: dfeb8dfa5af13e33ea3b9117f78183c08e76aec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


from itsdangerous import URLSafeTimedSerializer
import conf
from bootstrap import application


def generate_confirmation_token(email):
    serializer = URLSafeTimedSerializer(application.config['SECRET_KEY'])
    return serializer.dumps(email, salt=application.config['SECURITY_PASSWORD_SALT'])


def confirm_token(token):
    serializer = URLSafeTimedSerializer(application.config['SECRET_KEY'])
    try:
        email = serializer.loads(
            token,
            salt=application.config['SECURITY_PASSWORD_SALT'],
            max_age=conf.TOKEN_VALIDITY_PERIOD
        )
    except:
        return False
    return email
bgstack15