add login

This commit is contained in:
David Rodenkirchen
2024-08-25 22:31:29 +02:00
parent 8a47e95c2a
commit e6b7f4ca85
8 changed files with 216 additions and 60 deletions
+7 -1
View File
@@ -16,9 +16,12 @@ class UserService:
def __init__(self, db_service: DatabaseService) -> None:
self._db_service = db_service
def get_user(self, accessor: Union[str, int]) -> Optional[User]:
def get_user(self, accessor: Optional[Union[str, int]]) -> Optional[User]:
if accessor is None:
return
if isinstance(accessor, int):
return self._db_service.get_user_by_id(accessor)
accessor = accessor.lower()
if "@" in accessor:
return self._db_service.get_user_by_mail(accessor)
return self._db_service.get_user_by_name(accessor)
@@ -34,6 +37,8 @@ class UserService:
if disallowed_char:
raise NameNotAllowedError(disallowed_char)
user_name = user_name.lower()
hashed_pw = sha256(password_clear_text.encode(encoding="utf-8")).hexdigest()
return self._db_service.create_user(user_name, user_mail, hashed_pw)
@@ -41,6 +46,7 @@ class UserService:
disallowed_char = self._check_for_disallowed_char(user.user_name)
if disallowed_char:
raise NameNotAllowedError(disallowed_char)
user.user_name = user.user_name.lower()
return self._db_service.update_user(user)
def is_login_valid(self, user_name_or_mail: str, password_clear_text: str) -> bool: