34 lines
1.2 KiB
Python
Executable File
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 |