完善前端

This commit is contained in:
chenxin committed 2026-09-21 11:19:07 +08:00
1 parent 7c57d27494
commit b63542add3
81 files changed
+12075 -1441

No files matched your search

+14 -2
View File
@@ -7,6 +7,7 @@
from fastapi import APIRouter, HTTPException, Request, Response, status
from app.core.config import get_settings
from app.auth.service import (
SESSION_COOKIE,
create_session,
@@ -17,6 +18,8 @@ from app.models import PersonalDomain, User
router = APIRouter(prefix="/v1/auth", tags=["auth"])
settings = get_settings()
@router.post("/sessions", status_code=201)
async def dev_login(
@@ -32,11 +35,20 @@ async def dev_login(
(await db.execute(select(User).where(User.email == email))).scalar_one_or_none()
)
if existing is None:
user = User(email=email, display_name=email.split("@")[0])
admin_emails = {e.strip().lower() for e in settings.dev_admin_emails.split(",") if e.strip()}
user = User(
email=email,
display_name=email.split("@")[0],
role="admin" if email in admin_emails else "user",
)
db.add(user)
await db.flush()
domain = PersonalDomain(user_id=user.id, name="默认镜域")
db.add(domain)
await db.flush()
from app.characters.seeds import seed_default_character
await seed_default_character(db, domain.id)
else:
user = existing
_, token, csrf = await create_session(db, user.id)
@@ -49,7 +61,7 @@ async def dev_login(
samesite="lax",
path="/",
)
return {"csrf_token": csrf, "user_id": user.id}
return {"csrf_token": csrf, "user_id": user.id, "role": user.role, "email": user.email}
@router.delete("/sessions/current", status_code=204)