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.
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
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
|