Отлажен класс SessionManager

This commit is contained in:
2026-07-14 12:56:07 +03:00
parent 5c39031f04
commit 54d717369a
2 changed files with 48 additions and 12 deletions

View File

@@ -47,16 +47,17 @@ class SessionManager[T:SessionModel]:
:return: Объект данных сессии
"""
# Отсекаем ошибки активности и регистрации
reason = AccountManager.check_username_auth(username)
if reason is not None:
cls._raise_auth_error(reason)
# noinspection PyTypeChecker
account: AccountModel | None = authenticate(username=username, password=password)
# Обрабатываем ошибки
# Обрабатываем ошибки проверки пароля
if account is None:
cls._raise_auth_error(AuthRejectReason.INVALID_USERNAME_OR_PASSWORD)
elif not account.is_active:
cls._raise_auth_error(AuthRejectReason.ACCOUNT_IS_NOT_ACTIVE)
elif account.joined_at is None:
cls._raise_auth_error(AuthRejectReason.REGISTRATION_IS_NOT_COMPLETE)
# Создаем и возвращаем объект сессии
AccountManager.restore_account(account)
@@ -145,11 +146,15 @@ class SessionManager[T:SessionModel]:
if cls.__model_class is None:
model_path = ConfigurationManager.get_string("AUTH_SESSION_MODEL", "net_xeaf_rack.SessionModel")
app_label, model_name = model_path.split(".")
model = apps.get_model(app_label, model_name)
try:
model = apps.get_model(app_label, model_name)
except LookupError:
model = None
# Нет класса
if not model:
raise ImproperlyConfigured("AUTH_SESSION_MODEL must be set in settings.py")
raise ImproperlyConfigured("Correct AUTH_SESSION_MODEL must be set in settings.py")
# Некорректный класс
if not issubclass(model, SessionModel):