Refactor: Auth & Identity System v1.4
- Fix: Resolved SQLAlchemy Mapper error for 'UserVehicle' using string-based relationships. - Fix: Fixed Postgres Enum case sensitivity issue for 'userrole' (forcing lowercase 'user'). - Fix: Resolved ImportError for 'create_access_token' in security module. - Feature: Implemented 2-step registration protocol (Lite Register -> KYC Step). - Data: Added bank-level KYC fields (mother's name, ID/Driver/Boat/Pilot license expiry and categories). - Business: Applied private fleet isolation (is_transferable=False for individual orgs). - Docs: Updated Grand Master Book to v1.4 and added Developer Pitfalls guide.
This commit is contained in:
44
backend/app/api/v1/endpoints/auth.py
Executable file → Normal file
44
backend/app/api/v1/endpoints/auth.py
Executable file → Normal file
@@ -1,34 +1,32 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
# /opt/docker/dev/service_finder/backend/app/api/v1/endpoints/auth.py
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status, Body
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.db.session import get_db
|
||||
from app.schemas.auth import UserRegister, UserLogin, Token
|
||||
from app.schemas.auth import UserRegister, Token, UserLogin
|
||||
from app.services.auth_service import AuthService
|
||||
from app.core.security import create_access_token
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/register", status_code=status.HTTP_201_CREATED)
|
||||
@router.post("/register", response_model=Token, status_code=status.HTTP_201_CREATED)
|
||||
async def register(
|
||||
request: Request,
|
||||
user_in: UserRegister,
|
||||
request: Request,
|
||||
user_in: UserRegister = Body(...),
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
# 1. Email check
|
||||
is_available = await AuthService.check_email_availability(db, user_in.email)
|
||||
if not is_available:
|
||||
# 1. Foglalt email ellenőrzése
|
||||
if not await AuthService.check_email_availability(db, user_in.email):
|
||||
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
|
||||
# 2. Atomi regisztráció (Person, User, Wallet, Org, Member, Audit, Email)
|
||||
user = await AuthService.register_new_user(
|
||||
db=db,
|
||||
user_in=user_in,
|
||||
ip_address=request.client.host
|
||||
)
|
||||
|
||||
# 3. Token kiállítása
|
||||
token_data = {"sub": str(user.id), "email": user.email}
|
||||
access_token = create_access_token(data=token_data)
|
||||
|
||||
return {"access_token": access_token, "token_type": "bearer"}
|
||||
Reference in New Issue
Block a user