Отлажен класс SessionManager
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"""
|
||||
Описание класса AccountManager
|
||||
"""
|
||||
|
||||
from net.xeaf.rack.enums import AuthRejectReason
|
||||
from net.xeaf.rack.models.account_model import AccountModel
|
||||
|
||||
|
||||
@@ -17,14 +17,45 @@ class AccountManager:
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def check_account(cls, username: str) -> None:
|
||||
def check_account_auth(cls, account: AccountModel | None) -> AuthRejectReason | None:
|
||||
"""
|
||||
Проверяет Аккаунт с указанным именем
|
||||
Проверяет возможность авторизации Аккаунта
|
||||
|
||||
:param account: Аккаунт
|
||||
:return: Причина отказа в авторизации или None, если авторизация возможна
|
||||
"""
|
||||
|
||||
account = AccountModel.objects.filter(username=username).first()
|
||||
if account is None:
|
||||
raise ValueError("Account not found")
|
||||
return AuthRejectReason.INVALID_USERNAME_OR_PASSWORD
|
||||
if not account.is_active:
|
||||
return AuthRejectReason.ACCOUNT_IS_NOT_ACTIVE
|
||||
if account.joined_at is None:
|
||||
return AuthRejectReason.REGISTRATION_IS_NOT_COMPLETE
|
||||
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def check_username_auth(cls, username: str) -> AuthRejectReason | None:
|
||||
"""
|
||||
Проверяет возможность авторизации Аккаунта с заданным именем
|
||||
|
||||
:param username: Имя Аккаунта
|
||||
:return: Причина отказа в авторизации или None, если авторизация возможна
|
||||
"""
|
||||
|
||||
account = cls.find_by_username(username)
|
||||
return cls.check_account_auth(account)
|
||||
|
||||
@classmethod
|
||||
def find_by_username(cls, username: str) -> AccountModel | None:
|
||||
"""
|
||||
Возвращает Аккаунт с указанным именем
|
||||
|
||||
:param username: Имя Аккаунта
|
||||
:return: Аккаунт или None, если Аккаунт не найден
|
||||
"""
|
||||
|
||||
return AccountModel.objects.filter(username=username).first()
|
||||
|
||||
@classmethod
|
||||
def restore_account(cls, account: AccountModel) -> None:
|
||||
|
||||
Reference in New Issue
Block a user