tests-passed
This commit is contained in:
@@ -6,11 +6,12 @@
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy.orm import exc
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from auth.orm import Author
|
||||
from auth.state import AuthState
|
||||
from auth.tokens.storage import TokenStorage as TokenManager
|
||||
from orm.community import CommunityAuthor
|
||||
from services.db import local_session
|
||||
from settings import ADMIN_EMAILS as ADMIN_EMAILS_LIST
|
||||
from utils.logger import root_logger as logger
|
||||
@@ -45,16 +46,11 @@ async def verify_internal_auth(token: str) -> tuple[int, list, bool]:
|
||||
|
||||
with local_session() as session:
|
||||
try:
|
||||
author = session.query(Author).filter(Author.id == payload.user_id).one()
|
||||
author = session.query(Author).where(Author.id == payload.user_id).one()
|
||||
|
||||
# Получаем роли
|
||||
from orm.community import CommunityAuthor
|
||||
|
||||
ca = session.query(CommunityAuthor).filter_by(author_id=author.id, community_id=1).first()
|
||||
if ca:
|
||||
roles = ca.role_list
|
||||
else:
|
||||
roles = []
|
||||
roles = ca.role_list if ca else []
|
||||
logger.debug(f"[verify_internal_auth] Роли пользователя: {roles}")
|
||||
|
||||
# Определяем, является ли пользователь администратором
|
||||
@@ -64,7 +60,7 @@ async def verify_internal_auth(token: str) -> tuple[int, list, bool]:
|
||||
)
|
||||
|
||||
return int(author.id), roles, is_admin
|
||||
except exc.NoResultFound:
|
||||
except NoResultFound:
|
||||
logger.warning(f"[verify_internal_auth] Пользователь с ID {payload.user_id} не найден в БД или не активен")
|
||||
return 0, [], False
|
||||
|
||||
@@ -104,9 +100,6 @@ async def authenticate(request) -> AuthState:
|
||||
Returns:
|
||||
AuthState: Состояние аутентификации
|
||||
"""
|
||||
from auth.decorators import get_auth_token
|
||||
from utils.logger import root_logger as logger
|
||||
|
||||
logger.debug("[authenticate] Начало аутентификации")
|
||||
|
||||
# Создаем объект AuthState
|
||||
@@ -117,12 +110,16 @@ async def authenticate(request) -> AuthState:
|
||||
auth_state.token = None
|
||||
|
||||
# Получаем токен из запроса
|
||||
token = get_auth_token(request)
|
||||
token = request.headers.get("Authorization")
|
||||
if not token:
|
||||
logger.info("[authenticate] Токен не найден в запросе")
|
||||
auth_state.error = "No authentication token"
|
||||
return auth_state
|
||||
|
||||
# Обработка формата "Bearer <token>" (если токен не был обработан ранее)
|
||||
if token and token.startswith("Bearer "):
|
||||
token = token.replace("Bearer ", "", 1).strip()
|
||||
|
||||
logger.debug(f"[authenticate] Токен найден, длина: {len(token)}")
|
||||
|
||||
# Проверяем токен
|
||||
|
Reference in New Issue
Block a user