From 47ab22c534f495b3604315e1a3bfb6e56682dc7d Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Thu, 22 Aug 2019 09:35:23 +0200 Subject: [PATCH] Codestyle --- app/models.py | 21 ++++++++++++--------- config.py | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models.py b/app/models.py index 9c8327ba..05a5484a 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,6 @@ from flask import current_app from flask_login import UserMixin, AnonymousUserMixin -from itsdangerous import TimedJSONWebSignatureSerializer as Serializer +from itsdangerous import BadSignature, TimedJSONWebSignatureSerializer from werkzeug.security import generate_password_hash, check_password_hash from . import db from . import login_manager @@ -22,8 +22,8 @@ class Permission: class Role(db.Model): """ - Model for the different roles Users can have. Is a one-to-many relationship. - A Role can be associated with many User rows. + Model for the different roles Users can have. Is a one-to-many + relationship. A Role can be associated with many User rows. """ __tablename__ = 'roles' # Primary key @@ -136,24 +136,26 @@ class User(UserMixin, db.Model): """ Generates a confirmation token for user confirmation via email. """ - s = Serializer(current_app.config['SECRET_KEY'], expiration) + s = TimedJSONWebSignatureSerializer(current_app.config['SECRET_KEY'], + expiration) return s.dumps({'confirm': self.id}).decode('utf-8') def generate_reset_token(self, expiration=3600): """ Generates a reset token for password reset via email. """ - s = Serializer(current_app.config['SECRET_KEY'], expiration) + s = TimedJSONWebSignatureSerializer(current_app.config['SECRET_KEY'], + expiration) return s.dumps({'reset': self.id}).decode('utf-8') def confirm(self, token): """ Confirms User if the given token is valid and not expired. """ - s = Serializer(current_app.config['SECRET_KEY']) + s = TimedJSONWebSignatureSerializer(current_app.config['SECRET_KEY']) try: data = s.loads(token.encode('utf-8')) - except: + except BadSignature: return False if data.get('confirm') != self.id: return False @@ -166,10 +168,10 @@ class User(UserMixin, db.Model): """ Resets password for User if the given token is valid and not expired. """ - s = Serializer(current_app.config['SECRET_KEY']) + s = TimedJSONWebSignatureSerializer(current_app.config['SECRET_KEY']) try: data = s.loads(token.encode('utf-8')) - except: + except BadSignature: return False user = User.query.get(data.get('reset')) if user is None: @@ -291,6 +293,7 @@ class Corpus(db.Model): 'title': self.title, 'user_id': self.user_id} + ''' ' Flask-Login is told to use the application’s custom anonymous user by setting ' its class in the login_manager.anonymous_user attribute. diff --git a/config.py b/config.py index 65731c51..b52da6e2 100644 --- a/config.py +++ b/config.py @@ -33,7 +33,8 @@ class Config: class DevelopmentConfig(Config): DEBUG = True - SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data_dev.sqlite') + SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, + 'data_dev.sqlite') class TestingConfig(Config):