Files
ToDoList/api/app/schemas/auth.py
祀梦 f838840bda feat: add onboarding setup flow with nickname and password
Replace default auto-generated password with a first-run setup page that
lets users choose their own nickname and password. The /auth/setup endpoint
now accepts an optional nickname field (also sets site_name). Remove
set_default_password() since setup is now mandatory before login.
2026-05-17 19:45:36 +08:00

49 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from typing import Optional
from pydantic import BaseModel, Field, field_validator
class LoginRequest(BaseModel):
password: str = Field(..., min_length=1, max_length=100)
class LoginResponse(BaseModel):
message: str = "登录成功"
class ChangePasswordRequest(BaseModel):
old_password: str = Field(..., min_length=1, max_length=100)
new_password: str = Field(..., min_length=6, max_length=100)
@field_validator("new_password")
@classmethod
def validate_password_strength(cls, v: str) -> str:
if len(v) < 6:
raise ValueError("密码长度至少6位")
if len(set(v)) < 3:
raise ValueError("密码不能过于简单需包含至少3种不同字符")
return v
class AuthStatusResponse(BaseModel):
authenticated: bool
user_id: str
class SetupPasswordRequest(BaseModel):
password: str = Field(..., min_length=6, max_length=100)
nickname: Optional[str] = Field(None, min_length=1, max_length=50)
@field_validator("password")
@classmethod
def validate_password_strength(cls, v: str) -> str:
if len(v) < 6:
raise ValueError("密码长度至少6位")
if len(set(v)) < 3:
raise ValueError("密码不能过于简单需包含至少3种不同字符")
return v
class AuthSetupStatusResponse(BaseModel):
has_password: bool