mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-12-05 02:31:33 +00:00
Reduce user_ops.py line length to better fit webIDE
This commit is contained in:
parent
cf8a9d7e81
commit
d7f272a535
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user