Files
MokPyo/app/api/v1/endpoints.py

45 lines
1.2 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.core import settings, get_current_user, hash_password, verify_password
from app.db import get_db
from pathlib import Path
router = APIRouter()
# =========================
# TEST / PING
# =========================
@router.get("/ping", tags=["Test"])
def ping():
return {"message": "pong"}
# =========================
# EXEMPLE UTILISATEUR
# =========================
@router.get("/me", tags=["User"])
def read_current_user(current_user: dict = Depends(get_current_user)):
"""
Retourne les infos de l'utilisateur connecté
"""
return {"user": current_user}
# =========================
# EXEMPLE AUTH
# =========================
@router.post("/hash-password", tags=["Auth"])
def test_hash_password(password: str):
"""
Exemple simple pour hasher un mot de passe
"""
hashed = hash_password(password)
return {"password": password, "hashed": hashed}
@router.post("/verify-password", tags=["Auth"])
def test_verify_password(password: str, hashed: str):
"""
Vérifie qu'un mot de passe correspond à un hash
"""
valid = verify_password(password, hashed)
return {"valid": valid}