Files
ppr-ng/backend/app/api/deps.py
James Pattinson 8a94ce0f5b Initial commit: NextGen PPR System
- FastAPI backend with JWT authentication
- MySQL database with full schema
- Docker Compose orchestration
- CSV data import for 43,208 airports and 519,999 aircraft
- Complete PPR management API
- Modernized replacement for PHP-based system
2025-10-21 17:33:19 +00:00

47 lines
1.3 KiB
Python

from typing import Generator
from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from sqlalchemy.orm import Session
from app.db.session import SessionLocal
from app.core.security import verify_token
from app.crud.crud_user import user as crud_user
security = HTTPBearer()
def get_db() -> Generator:
"""Database dependency"""
try:
db = SessionLocal()
yield db
finally:
db.close()
async def get_current_user(
db: Session = Depends(get_db),
credentials: HTTPAuthorizationCredentials = Depends(security)
):
"""Get current authenticated user"""
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
headers={"WWW-Authenticate": "Bearer"},
)
username = verify_token(credentials.credentials)
if username is None:
raise credentials_exception
user = crud_user.get_by_username(db, username=username)
if user is None:
raise credentials_exception
return user
def get_current_active_user(
current_user = Depends(get_current_user),
):
"""Get current active user (for future use if we add user status)"""
return current_user