2025-12-04 10:04:21 +08:00

74 lines
1.8 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.

# app/models/schemas/users.py
from typing import Optional
from pydantic import BaseModel, EmailStr, Field
from app.models.domain.users import User
from app.models.schemas.rwschema import RWSchema
# ===============================
# 旧有登录/创建(兼容保留)
# ===============================
class UserInLogin(RWSchema):
email: EmailStr
password: str
class UserInCreate(UserInLogin):
username: str
class UserInUpdate(BaseModel):
username: Optional[str] = None
email: Optional[EmailStr] = None
password: Optional[str] = None
bio: Optional[str] = None
image: Optional[str] = None
phone: Optional[str] = None
user_type: Optional[str] = None
company_name: Optional[str] = None
# ===============================
# 新增:邮箱验证码注册/登录/Token
# ===============================
class SendEmailCodeIn(RWSchema):
"""发送邮箱验证码"""
email: EmailStr
# 可选场景register/reset/login不传默认 register
scene: Optional[str] = "register"
class RegisterWithEmailIn(RWSchema):
"""邮箱注册:邮箱 + 密码 + 确认密码 + 验证码"""
email: EmailStr
password: str = Field(min_length=6, max_length=64)
confirm_password: str = Field(min_length=6, max_length=64)
code: str = Field(min_length=4, max_length=8)
class LoginWithPasswordIn(RWSchema):
"""邮箱 + 密码登录"""
email: EmailStr
password: str
class TokenOut(RWSchema):
token: str
token_type: str = "Token"
# ===============================
# 响应模型(带 email_verified
# ===============================
class UserWithToken(User):
token: str
phone: Optional[str] = None
user_type: Optional[str] = None
company_name: Optional[str] = None
class UserInResponse(RWSchema):
user: UserWithToken