This commit is contained in:
@@ -106,27 +106,29 @@ def login_accepted(f):
|
||||
async def decorated_function(*args, **kwargs):
|
||||
info = args[1]
|
||||
req = info.context.get("request")
|
||||
|
||||
# Пробуем получить данные авторизации
|
||||
|
||||
logger.debug("login_accepted: Проверка авторизации пользователя.")
|
||||
user_id, user_roles = await check_auth(req)
|
||||
|
||||
logger.debug(f"login_accepted: user_id={user_id}, user_roles={user_roles}")
|
||||
|
||||
if user_id and user_roles:
|
||||
# Если пользователь авторизован, добавляем его данные в контекст
|
||||
logger.info(f" got {user_id} roles: {user_roles}")
|
||||
logger.info(f"login_accepted: Пользователь авторизован: {user_id} с ролями {user_roles}")
|
||||
info.context["user_id"] = user_id.strip()
|
||||
info.context["roles"] = user_roles
|
||||
|
||||
# Пробуем получить профиль автора
|
||||
author = await get_cached_author_by_user_id(user_id, get_with_stat)
|
||||
if not author:
|
||||
logger.warning(f"author profile not found for user {user_id}")
|
||||
info.context["author"] = author
|
||||
if author:
|
||||
logger.debug(f"login_accepted: Найден профиль автора: {author}")
|
||||
# Предполагается, что `author` является объектом с атрибутом `id`
|
||||
info.context["author"] = author.dict()
|
||||
else:
|
||||
logger.error(f"login_accepted: Профиль автора не найден для пользователя {user_id}. Используем базовые данные.")# Используем базовую информацию об автор
|
||||
else:
|
||||
# Для неавторизованных пользователей очищаем контекст
|
||||
logger.debug("login_accepted: Пользователь не авторизован. Очищаем контекст.")
|
||||
info.context["user_id"] = None
|
||||
info.context["roles"] = None
|
||||
info.context["author"] = None
|
||||
|
||||
return await f(*args, **kwargs)
|
||||
|
||||
return decorated_function
|
||||
|
Reference in New Issue
Block a user