All checks were successful
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 9s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 12s
Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
"""Auth endpoints: login, logout, registration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from auth import login, logout, require_auth
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel, Field
|
|
from services.registration import register_system_admin, setup_status
|
|
|
|
router = APIRouter(prefix="/api/auth", tags=["auth"])
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
email: str = Field(min_length=3, max_length=255)
|
|
password: str = Field(min_length=8, max_length=256)
|
|
|
|
|
|
class RegisterRequest(BaseModel):
|
|
email: str = Field(min_length=3, max_length=255)
|
|
password: str = Field(min_length=8, max_length=256)
|
|
display_name: str = Field(min_length=1, max_length=255)
|
|
organization_name: str | None = Field(default=None, max_length=255)
|
|
|
|
|
|
@router.get("/setup-status")
|
|
def auth_setup_status():
|
|
return setup_status()
|
|
|
|
|
|
@router.post("/register")
|
|
def auth_register(body: RegisterRequest):
|
|
"""Erster User wird Portal-Systemadmin inkl. Default-Tenant."""
|
|
return register_system_admin(
|
|
email=body.email,
|
|
password=body.password,
|
|
display_name=body.display_name,
|
|
organization_name=body.organization_name,
|
|
)
|
|
|
|
|
|
@router.post("/login")
|
|
def auth_login(body: LoginRequest):
|
|
return login(body.email, body.password)
|
|
|
|
|
|
@router.post("/logout")
|
|
def auth_logout(session: dict = Depends(require_auth)):
|
|
token = session.get("token")
|
|
if token:
|
|
logout(token)
|
|
return {"ok": True}
|