- Split mother's name in KYC (last/first) - Added mileage_unit and fuel_type to Assets - Expanded AssetCost for international VAT and original currency - Fixed SQLAlchemy IndexError in asset catalog lookup - Added exchange_rate and ratings tables to models
57 lines
1.7 KiB
Python
Executable File
57 lines
1.7 KiB
Python
Executable File
from typing import Optional
|
|
import logging
|
|
from fastapi import Depends, HTTPException, status
|
|
from fastapi.security import OAuth2PasswordBearer
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy import select
|
|
|
|
from app.db.session import get_db
|
|
from app.core.security import decode_token
|
|
from app.models.identity import User
|
|
|
|
logger = logging.getLogger(__name__)
|
|
reusable_oauth2 = OAuth2PasswordBearer(tokenUrl="/api/v1/auth/login")
|
|
|
|
async def get_current_user(
|
|
db: AsyncSession = Depends(get_db),
|
|
token: str = Depends(reusable_oauth2),
|
|
) -> User:
|
|
"""
|
|
Dependency, amely visszaadja az aktuálisan bejelentkezett felhasználót.
|
|
Támogatja a 'dev_bypass_active' tokent a fejlesztői teszteléshez.
|
|
"""
|
|
# FEJLESZTŐI BYPASS
|
|
if token == "dev_bypass_active":
|
|
result = await db.execute(select(User).where(User.id == 1))
|
|
return result.scalar_one()
|
|
|
|
payload = decode_token(token)
|
|
if not payload:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Érvénytelen vagy lejárt munkamenet."
|
|
)
|
|
|
|
user_id: str = payload.get("sub")
|
|
if not user_id:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Token azonosítási hiba."
|
|
)
|
|
|
|
result = await db.execute(select(User).where(User.id == int(user_id)))
|
|
user = result.scalar_one_or_none()
|
|
|
|
if not user:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="A felhasználó nem található."
|
|
)
|
|
|
|
if user.is_deleted:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_403_FORBIDDEN,
|
|
detail="Ez a fiók korábban törlésre került."
|
|
)
|
|
|
|
return user |