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
This commit is contained in:
47
backend/app/api/deps.py
Normal file
47
backend/app/api/deps.py
Normal file
@@ -0,0 +1,47 @@
|
||||
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
|
||||
Reference in New Issue
Block a user