Files
stock/backend/app/schemas/auth.py
2026-06-11 01:41:47 +08:00

48 lines
1013 B
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 pydantic import BaseModel, EmailStr, field_validator
import re
class RegisterRequest(BaseModel):
username: str
email: EmailStr
password: str
@field_validator("username")
@classmethod
def username_alphanumeric(cls, v: str) -> str:
if not re.match(r"^[a-zA-Z0-9_]{3,20}$", v):
raise ValueError("用户名只能包含字母、数字、下划线长度3-20位")
return v
@field_validator("password")
@classmethod
def password_min_length(cls, v: str) -> str:
if len(v) < 6:
raise ValueError("密码至少6位")
return v
class LoginRequest(BaseModel):
username: str
password: str
class TokenResponse(BaseModel):
access_token: str
refresh_token: str
token_type: str = "bearer"
class RefreshRequest(BaseModel):
refresh_token: str
class UserOut(BaseModel):
id: int
username: str
email: str
is_active: bool
is_admin: bool
model_config = {"from_attributes": True}