aboutsummaryrefslogtreecommitdiff
path: root/src/web/lib/user_utils.py
blob: f78a6ed666c64e5072d182f92717aad40a531545 (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(nickname):
    serializer = URLSafeTimedSerializer(application.config['SECRET_KEY'])
    return serializer.dumps(nickname, salt=application.config['SECURITY_PASSWORD_SALT'])


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