优化后台界面与无操作退出体验

This commit is contained in:
Cheng Zhou
2026-06-10 15:20:06 +08:00
parent ea3f19e241
commit 84e55af8fe
39 changed files with 793 additions and 608 deletions
-27
View File
@@ -39,15 +39,6 @@ class ExtendResponse(BaseModel):
expiresAt: datetime
class UnlockRequest(LoginRequest):
pass
class UnlockResponse(BaseModel):
accessToken: str
expiresAt: datetime
router = APIRouter()
AVATAR_ROOT = Path(__file__).resolve().parent.parent.parent / "uploads" / "avatars"
AVATAR_ROOT.mkdir(parents=True, exist_ok=True)
@@ -197,24 +188,6 @@ async def extend_access_token(
return ExtendResponse(accessToken=new_token, expiresAt=expires_at)
@router.post("/unlock", response_model=UnlockResponse)
async def unlock_session(
payload: UnlockRequest,
db: AsyncSession = Depends(get_db_session),
) -> UnlockResponse:
db_user = await authenticate_encrypted_password(payload, db)
if db_user.status != UserStatus.ACTIVE:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="账号已停用")
session_start = datetime.now(timezone.utc)
access_token = create_access_token(
user_id=str(db_user.id),
expires_minutes=None,
session_start=session_start,
)
expires_at = session_start + timedelta(minutes=settings.JWT_EXPIRE_MINUTES)
return UnlockResponse(accessToken=access_token, expiresAt=expires_at)
@router.patch("/me", response_model=UserRead)
async def update_me(
payload: UserSelfUpdate,
-12
View File
@@ -358,15 +358,3 @@ async def test_login_challenge_cannot_be_reused(client_and_db):
assert first.status_code == 200
assert second.status_code == 401
@pytest.mark.asyncio
async def test_unlock_requires_encrypted_password(client_and_db):
client, _ = client_and_db
plaintext = await client.post("/api/v1/auth/unlock", json={"email": "admin@test.com", "password": "admin123"})
encrypted = await client.post(
"/api/v1/auth/unlock",
json=await encrypted_auth_payload(client, "admin@test.com", "admin123"),
)
assert plaintext.status_code == 422
assert encrypted.status_code == 200