Skip to content

Commit

Permalink
Added user service auth method.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhand committed Sep 1, 2023
1 parent 86a11b6 commit 4e983cc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/dioptra/restapi/user/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ def delete(self, user_id: int, **kwargs) -> list[int]:

return [user_id]

def authenticate_user(
self,
name: str,
password: str,
**kwargs,
) -> User | None:
log: BoundLogger = kwargs.get("log", LOGGER.new())
for user in self.get_all():
if user.username == name:
if self._password_service.verify(
password=password, hashed_password=user.password
):
return user
break

return None

@staticmethod
def get_all(**kwargs) -> list[User]:
log: BoundLogger = kwargs.get("log", LOGGER.new())
Expand Down

0 comments on commit 4e983cc

Please sign in to comment.