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()