Files
InsightRadar/backend/app/schemas/auth_schema.py
2026-03-11 01:33:21 +08:00

57 lines
1.4 KiB
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, ConfigDict, Field
from app.models.models import GenderType
EMAIL_PATTERN = r"^[^@\s]+@[^@\s]+\.[^@\s]+$"
class RegisterCodeSendRequest(BaseModel):
email: str = Field(..., max_length=150, pattern=EMAIL_PATTERN)
class LoginCodeSendRequest(BaseModel):
email: str = Field(..., max_length=150, pattern=EMAIL_PATTERN)
class RegisterRequest(BaseModel):
email: str = Field(..., max_length=150, pattern=EMAIL_PATTERN)
password: str = Field(..., min_length=8, max_length=128)
verification_code: str = Field(..., pattern=r"^\d{6}$")
nickname: Optional[str] = Field(default=None, max_length=100)
class LoginRequest(BaseModel):
email: str = Field(..., max_length=150, pattern=EMAIL_PATTERN)
password: str = Field(..., min_length=8, max_length=128)
class LoginWithCodeRequest(BaseModel):
email: str = Field(..., max_length=150, pattern=EMAIL_PATTERN)
verification_code: str = Field(..., pattern=r"^\d{6}$")
class UserProfileResponse(BaseModel):
id: int
email: str
nickname: Optional[str]
avatar_url: Optional[str]
gender: GenderType
created_at: datetime
model_config = ConfigDict(from_attributes=True)
class AuthTokenResponse(BaseModel):
access_token: str
token_type: str = "bearer"
expires_in: int
user: UserProfileResponse
class MessageResponse(BaseModel):
message: str