- 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
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from datetime import datetime, timedelta, timezone
|
|
from typing import Optional, Dict, Any
|
|
import bcrypt
|
|
from jose import jwt, JWTError
|
|
from app.core.config import settings
|
|
|
|
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
|
"""Összehasonlítja a sima szöveges jelszót a hash-elt változattal."""
|
|
if not hashed_password:
|
|
return False
|
|
try:
|
|
return bcrypt.checkpw(
|
|
plain_password.encode("utf-8"),
|
|
hashed_password.encode("utf-8")
|
|
)
|
|
except Exception:
|
|
return False
|
|
|
|
def get_password_hash(password: str) -> str:
|
|
"""Létrehozza a jelszó hash-elt változatát."""
|
|
salt = bcrypt.gensalt()
|
|
return bcrypt.hashpw(password.encode("utf-8"), salt).decode("utf-8")
|
|
|
|
def create_access_token(data: Dict[str, Any], expires_delta: Optional[timedelta] = None) -> str:
|
|
"""Létrehozza a JWT access tokent."""
|
|
to_encode = data.copy()
|
|
if expires_delta:
|
|
expire = datetime.now(timezone.utc) + expires_delta
|
|
else:
|
|
expire = datetime.now(timezone.utc) + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
|
|
|
to_encode.update({"exp": expire})
|
|
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
|
|
return encoded_jwt
|
|
|
|
def decode_token(token: str) -> Optional[Dict[str, Any]]:
|
|
"""JWT token visszafejtése és validálása."""
|
|
try:
|
|
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
|
return payload
|
|
except JWTError:
|
|
return None |