66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
from pydantic import BaseModel, EmailStr, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
"""用户基础模型"""
|
|
username: str = Field(..., min_length=3, max_length=50, description="登录名")
|
|
nickname: str = Field(..., max_length=50, description="昵称")
|
|
email: Optional[EmailStr] = Field(None, max_length=50, description="电子邮箱")
|
|
phone: Optional[str] = Field(None, max_length=11, description="手机号码")
|
|
wx_openid: Optional[str] = Field(None, max_length=100, description="微信OpenID")
|
|
role_id: int = Field(2, description="角色ID")
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
"""用户创建模型"""
|
|
password: str = Field(..., min_length=6, max_length=50, description="密码")
|
|
|
|
|
|
class UserLogin(BaseModel):
|
|
"""用户登录模型"""
|
|
username: str = Field(..., description="登录名")
|
|
password: str = Field(..., description="密码")
|
|
|
|
|
|
class UserResponse(UserBase):
|
|
"""用户响应模型"""
|
|
id: int = Field(..., description="用户ID")
|
|
createtime: datetime = Field(..., description="创建时间")
|
|
lastlogintime: datetime = Field(..., description="最后登录时间")
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Token(BaseModel):
|
|
"""令牌模型"""
|
|
access_token: str = Field(..., description="访问令牌")
|
|
token_type: str = Field(..., description="令牌类型")
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
"""令牌数据模型"""
|
|
user_id: Optional[int] = None
|
|
email: Optional[EmailStr] = None
|
|
|
|
|
|
class RoleBase(BaseModel):
|
|
"""角色基础模型"""
|
|
name: str = Field(..., max_length=50, description="角色名称")
|
|
|
|
|
|
class RoleCreate(RoleBase):
|
|
"""角色创建模型"""
|
|
creator: Optional[str] = Field(None, max_length=50, description="创建人")
|
|
|
|
|
|
class RoleResponse(RoleBase):
|
|
"""角色响应模型"""
|
|
id: int = Field(..., description="角色ID")
|
|
createtime: datetime = Field(..., description="创建时间")
|
|
creator: Optional[str] = Field(None, description="创建人")
|
|
|
|
class Config:
|
|
from_attributes = True |