diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2016-02-02 23:15:37 +0100 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2016-02-02 23:15:37 +0100 |
commit | 082bf39a7dd7296d4f51b6b124d185135dc00989 (patch) | |
tree | 6e12cf2b67b016aff38874c389b5bf8b5242749a /src/web/controllers/user.py | |
parent | fixing logging (diff) | |
parent | reload and fold all button (diff) | |
download | newspipe-082bf39a7dd7296d4f51b6b124d185135dc00989.tar.gz newspipe-082bf39a7dd7296d4f51b6b124d185135dc00989.tar.bz2 newspipe-082bf39a7dd7296d4f51b6b124d185135dc00989.zip |
Merge branch 'feature/categories'
close #22
close #23
Diffstat (limited to 'src/web/controllers/user.py')
-rw-r--r-- | src/web/controllers/user.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/web/controllers/user.py b/src/web/controllers/user.py index 3f96b185..d8bf1fa1 100644 --- a/src/web/controllers/user.py +++ b/src/web/controllers/user.py @@ -1,3 +1,6 @@ +import random +import hashlib +from werkzeug import generate_password_hash from .abstract import AbstractController from web.models import User @@ -5,3 +8,25 @@ from web.models import User class UserController(AbstractController): _db_cls = User _user_id_key = 'id' + + def unset_activation_key(self, obj_id): + self.update({'id': obj_id}, {'activation_key': ""}) + + def set_activation_key(self, obj_id): + key = str(random.getrandbits(256)).encode("utf-8") + key = hashlib.sha512(key).hexdigest()[:86] + self.update({'id': obj_id}, {'activation_key': key}) + + def _handle_password(self, attrs): + if attrs.get('password'): + attrs['pwdhash'] = generate_password_hash(attrs.pop('password')) + elif 'password' in attrs: + del attrs['password'] + + def create(self, **attrs): + self._handle_password(attrs) + return super().create(**attrs) + + def update(self, filters, attrs): + self._handle_password(attrs) + return super().update(filters, attrs) |