memleketmeselesi/mm_api/dependencies.py
Mukan Erkin 2498e75594 init: memleketmeselesi platform — API + migrations
FastAPI + PostgreSQL 16. KYC, issue sistemi, permission/group yönetimi,
session yönetimi, API client auth (kışla kapısı), officials/persons CRUD.
Migration 0001–0013 dahil.
2026-04-27 23:06:59 +03:00

25 lines
878 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import Depends, HTTPException, Security
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from psycopg import AsyncConnection
from mm_api.db import get_conn
import mm_api.services.auth as auth_svc
bearer = HTTPBearer(auto_error=False)
async def current_user(
credentials: HTTPAuthorizationCredentials = Security(bearer),
conn: AsyncConnection = Depends(get_conn),
) -> dict:
if not credentials:
raise HTTPException(401, "Kimlik doğrulama gerekli")
user = await auth_svc.get_current_user(conn, credentials.credentials)
if not user:
raise HTTPException(401, "Geçersiz veya süresi dolmuş token")
return user
async def verified_user(user: dict = Depends(current_user)) -> dict:
if user["kyc_status"] != "verified":
raise HTTPException(403, "Kimlik doğrulaması gerekli")
return user