Files
service-finder/backend/app/api/v1/endpoints/auth.py
2026-02-04 21:58:57 +00:00

34 lines
1.2 KiB
Python
Executable File

from fastapi import APIRouter, Depends, HTTPException, Request, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.db.session import get_db
from app.schemas.auth import UserRegister, UserLogin, Token
from app.services.auth_service import AuthService
router = APIRouter()
@router.post("/register", status_code=status.HTTP_201_CREATED)
async def register(
request: Request,
user_in: UserRegister,
db: AsyncSession = Depends(get_db)
):
# 1. Email check
is_available = await AuthService.check_email_availability(db, user_in.email)
if not is_available:
raise HTTPException(status_code=400, detail="Az e-mail cím már foglalt.")
# 2. Process
try:
user = await AuthService.register_new_user(
db=db,
user_in=user_in,
ip_address=request.client.host
)
return {"status": "success", "message": "Regisztráció sikeres!"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Szerver hiba: {str(e)}")
@router.post("/login")
async def login(user_in: UserLogin, db: AsyncSession = Depends(get_db)):
# ... A korábbi login logika itt maradhat ...
pass