diff options
author | Michaël Ball <michael.ball@gmail.com> | 2017-03-26 10:19:59 +0100 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2017-06-04 07:37:53 +0100 |
commit | d06f96388d754ed41876f7fccb63f84241d44963 (patch) | |
tree | 640a4f3eaf7e1f2b76a246a1977c27775d0b59a1 /models/user.py | |
parent | caa1c3ccdf94ee20140b3964aab0ad3058e03699 (diff) |
Works on python 2/pypy
Diffstat (limited to 'models/user.py')
-rw-r--r-- | models/user.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/models/user.py b/models/user.py index 925df5e..ea90f39 100644 --- a/models/user.py +++ b/models/user.py @@ -1,11 +1,11 @@ -import os +from os import urandom -from flask.ext.login import make_secure_token +from itsdangerous import URLSafeTimedSerializer from common.security import pwd_context, secret_key -class User: +class User(object): def __init__(self, **kwargs): for (key, value) in kwargs.items(): setattr(self, key, value) @@ -43,16 +43,17 @@ class User: def new_password(self, password, category=None): if self.id: - hash = None + the_hash = None if category: - hash = pwd_context.encrypt(password, category=category) + the_hash = pwd_context.encrypt(password, category=category) else: - hash = pwd_context.encrypt(password) + the_hash = pwd_context.encrypt(password) - api_key = make_secure_token(hash, os.urandom(64), key=secret_key) + serializer = URLSafeTimedSerializer(password, salt=urandom(64)) + api_key = serializer.dumps(the_hash) - return hash, api_key + return the_hash, api_key else: raise ValueError("No user") |