feat: implement hybrid address system and premium search logic
- Added centralized, self-learning GeoService (ZIP, City, Street) - Implemented Hybrid Address Management (Centralized table + Denormalized fields) - Fixed Gamification logic (PointsLedger field names & filtering) - Added address autocomplete and two-tier (Free/Premium) search API - Synchronized UserStats and PointsLedger schemas
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import AsyncGenerator
|
||||
from typing import Optional
|
||||
from fastapi import Depends, HTTPException, status
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@@ -6,46 +6,50 @@ from sqlalchemy import select
|
||||
|
||||
from app.db.session import get_db
|
||||
from app.core.security import decode_token
|
||||
from app.models.identity import User # Javítva identity-re
|
||||
from app.models.identity import User
|
||||
|
||||
# Javítva v1-re
|
||||
# Az OAuth2 séma definiálása, ami a tokent keresi a Headerben
|
||||
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.
|
||||
Ha a token érvénytelen vagy a felhasználó nem létezik, hibát dob.
|
||||
"""
|
||||
payload = decode_token(token)
|
||||
if not payload:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Érvénytelen vagy lejárt token."
|
||||
detail="Érvénytelen vagy lejárt munkamenet."
|
||||
)
|
||||
|
||||
user_id = payload.get("sub")
|
||||
user_id: str = payload.get("sub")
|
||||
if not user_id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Token azonosítási hiba."
|
||||
)
|
||||
|
||||
# Felhasználó keresése az adatbázisban
|
||||
res = await db.execute(select(User).where(User.id == int(user_id)))
|
||||
user = res.scalar_one_or_none()
|
||||
# Felhasználó lekérése az adatbázisból
|
||||
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="Felhasználó nem található."
|
||||
detail="A felhasználó nem található."
|
||||
)
|
||||
|
||||
if user.is_deleted:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Ez a fiók törölve lett."
|
||||
detail="Ez a fiók korábban törlésre került."
|
||||
)
|
||||
|
||||
# FONTOS: Itt NEM dobunk hibát, ha user.is_active == False,
|
||||
# mert a Step 2 (KYC) kitöltéséhez be kell tudnia lépni inaktívként is!
|
||||
# Megjegyzés: is_active ellenőrzést szándékosan nem teszünk itt,
|
||||
# hogy a KYC folyamatot (Step 2) be tudja fejezni a még nem aktív user is.
|
||||
|
||||
return user
|
||||
Reference in New Issue
Block a user