mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
add websockets suppor97
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
"""Application configuration"""
|
"""Application configuration"""
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
from pydantic import ConfigDict
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
@@ -32,9 +33,11 @@ class Settings(BaseSettings):
|
|||||||
if not self.DATABASE_URL:
|
if not self.DATABASE_URL:
|
||||||
self.DATABASE_URL = f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}"
|
self.DATABASE_URL = f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}"
|
||||||
|
|
||||||
class Config:
|
model_config = ConfigDict(
|
||||||
"""Pydantic config"""
|
env_file=".env",
|
||||||
env_file = ".env"
|
extra="allow", # Разрешаем дополнительные поля
|
||||||
|
case_sensitive=True # Учитываем регистр
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
@@ -3,11 +3,14 @@ from fastapi import Depends, HTTPException, status
|
|||||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||||
from passlib.context import CryptContext
|
from passlib.context import CryptContext
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
import re
|
import logging
|
||||||
|
|
||||||
from .jwt import verify_token
|
from .jwt import verify_token
|
||||||
from ..database import get_db
|
from ..database import get_db
|
||||||
|
|
||||||
|
# Настраиваем логирование
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||||
security = HTTPBearer(auto_error=False)
|
security = HTTPBearer(auto_error=False)
|
||||||
|
|
||||||
@@ -46,6 +49,7 @@ def get_current_admin(
|
|||||||
|
|
||||||
return {"is_admin": True}
|
return {"is_admin": True}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error(f"Authentication error: {e}")
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Invalid authentication credentials",
|
detail="Invalid authentication credentials",
|
||||||
@@ -78,7 +82,8 @@ def get_current_employee(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {"id": employee_id}
|
return {"id": employee_id}
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
logger.error(f"Authentication error: {e}")
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Invalid authentication credentials",
|
detail="Invalid authentication credentials",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from fastapi import HTTPException, status
|
|||||||
from redis import Redis
|
from redis import Redis
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from ..core.config import settings
|
from ..config import settings
|
||||||
from ..models.token import Token
|
from ..models.token import Token
|
||||||
from ..crud.employees import get_employee
|
from ..crud.employees import get_employee
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user