28 lines
849 B
Python
28 lines
849 B
Python
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel, Field, field_validator
|
|
|
|
|
|
class SetupRequest(BaseModel):
|
|
username: str = Field(min_length=2, max_length=40)
|
|
password: str = Field(min_length=10, max_length=128)
|
|
bootstrap_token: str | None = Field(default=None, max_length=512)
|
|
|
|
@field_validator("username")
|
|
@classmethod
|
|
def clean_username(cls, value: str) -> str:
|
|
cleaned = value.strip()
|
|
if not cleaned:
|
|
raise ValueError("用户名不能为空")
|
|
return cleaned
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
username: str = Field(min_length=1, max_length=40)
|
|
password: str = Field(min_length=1, max_length=128)
|
|
|
|
|
|
class PasswordChangeRequest(BaseModel):
|
|
current_password: str = Field(min_length=1, max_length=128)
|
|
new_password: str = Field(min_length=10, max_length=128)
|