From d7f272a535d53e729e867562bb0655436dd6b624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 4 Jun 2018 21:16:05 +0200 Subject: [PATCH] Reduce user_ops.py line length to better fit webIDE --- solvable/src/webservice/user_ops.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/solvable/src/webservice/user_ops.py b/solvable/src/webservice/user_ops.py index ac59294..c9107a6 100644 --- a/solvable/src/webservice/user_ops.py +++ b/solvable/src/webservice/user_ops.py @@ -23,9 +23,16 @@ class UserOps: :raises InvalidCredentialsError: User does not exist or password provided is invalid """ - user = self.db_session.query(User).filter(User.username == self.username).first() + user = self.db_session.query(User).filter( + User.username == self.username + ).first() - if not user or not PasswordHasher.verify(self.password, user.passwordhash): + passw_is_correct = PasswordHasher.verify( + self.password, + user.passwordhash + ) + + if not user or not passw_is_correct: self.log(f'Invalid credentials for user "{self.username}"!') raise InvalidCredentialsError @@ -39,11 +46,17 @@ class UserOps: :raises UserExistsError: A user with the provided username already exists """ - if self.db_session.query(User).filter(User.username == self.username).all(): + existing_users = self.db_session.query(User).filter( + User.username == self.username + ).all() + + if existing_users: raise UserExistsError - user = User(username=self.username, - passwordhash=PasswordHasher.hash(self.password)) + user = User( + username=self.username, + passwordhash=PasswordHasher.hash(self.password) + ) self.db_session.add(user) self.db_session.commit()