From a8672a8656c02a683aa8115f4985b4eb84b18279 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 19 May 2017 16:45:55 +0200 Subject: [PATCH] Cleanup user model. --- accountant/models/users.py | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/accountant/models/users.py b/accountant/models/users.py index 5b180f7..4cc514c 100644 --- a/accountant/models/users.py +++ b/accountant/models/users.py @@ -3,18 +3,12 @@ # vim: set tw=80 ts=4 sw=4 sts=4: from passlib.hash import sha256_crypt as crypt -from itsdangerous import (URLSafeTimedSerializer as Serializer, - BadSignature, SignatureExpired) -from flask import current_app as app - -from flask_login import UserMixin - -# pylint: disable=no-member,too-few-public-methods from . import db -class User(UserMixin, db.Model): +# pylint: disable=no-member,too-few-public-methods +class User(db.Model): """Class used to handle users.""" # pylint: disable=invalid-name id = db.Column(db.Integer, primary_key=True) @@ -24,6 +18,7 @@ class User(UserMixin, db.Model): server_default=db.true()) def is_active(self): + """Return True if user is active.""" return self.active @classmethod @@ -39,24 +34,3 @@ class User(UserMixin, db.Model): def verify_password(self, password): """Verify password passed in argument with the user's one.""" return crypt.verify(password, self.password) - - def generate_auth_token(self): - """Generate authentication token used to identify the session.""" - serializer = Serializer(app.secret_key) - - return serializer.dumps({'id': self.id}) - - @classmethod - def verify_auth_token(cls, token): - """Verify the authentication token and return the associated user.""" - serializer = Serializer(app.config['SECRET_KEY']) - - try: - data = serializer.loads(token, max_age=app.config["SESSION_TTL"]) - except SignatureExpired: - return None - except BadSignature: - return None - - user = cls.query().get(data['id']) - return user