login page

This commit is contained in:
zy7y
2022-09-11 18:34:18 +08:00
commit a1c23c8cf8
52 changed files with 4149 additions and 0 deletions

View File

36
backend/schemas/common.py Normal file
View File

@@ -0,0 +1,36 @@
"""公共模型"""
from typing import Generic, TypeVar
from pydantic import BaseModel, Field
from pydantic.generics import GenericModel
T = TypeVar("T")
class LoginForm(BaseModel):
"""用户登录参数"""
username: str = Field(..., description="账号", max_length=12, min_length=3)
password: str = Field(..., description="密码", min_length=6, max_length=16)
class LoginResult(BaseModel):
"""登录响应模型"""
id: int = Field(..., description="用户ID")
access_token: str = Field(..., description="token 串")
token_type: str = Field("Bearer", description="token 类型")
class QueryData(BaseModel):
"""分页查询基础数据"""
offset: int = 1
size: int = 10
class ListAll(GenericModel, Generic[T]):
"""查列表时的模型"""
total: int = Field(..., description="总数")
items: T = Field(..., description="数据列表")

6
backend/schemas/menu.py Normal file
View File

@@ -0,0 +1,6 @@
from tortoise.contrib.pydantic import pydantic_model_creator
from models import MenuModel
MenuRead = pydantic_model_creator(MenuModel, name="MenuOut")
MenuIn = pydantic_model_creator(MenuModel, name="MenuIn", exclude_readonly=True)

16
backend/schemas/role.py Normal file
View File

@@ -0,0 +1,16 @@
from pydantic import Field
from tortoise.contrib.pydantic import pydantic_model_creator
from models import RoleModel
RoleRed = pydantic_model_creator(RoleModel, name="RoleOut")
RoleIn = pydantic_model_creator(RoleModel, name="RoleIn", exclude_readonly=True)
class RoleAdd(RoleIn):
menus: list[int] = Field(..., description="菜单列表")
class RoleInfo(RoleRed):
pass

29
backend/schemas/user.py Normal file
View File

@@ -0,0 +1,29 @@
from typing import List, Optional
from pydantic import Field
from tortoise.contrib.pydantic import pydantic_model_creator
from models import UserModel, UserRoleModel
from schemas.common import QueryData
UserRead = pydantic_model_creator(UserModel, name="UserOut", exclude=("password",))
UserIn = pydantic_model_creator(UserModel, name="UserIn", exclude_readonly=True)
UserRole = pydantic_model_creator(UserRoleModel, name="UserRole", exclude_readonly=True)
class UserInfo(UserRead):
active_rid: int = Field(..., description="用户当前激活角色")
rids: List[int] = Field(..., description="用户拥有角色")
class UserAdd(UserIn):
rids: List[int] = Field(..., description="用户角色列表")
class UserQuery(QueryData):
username: Optional[str] = Field("", description="用户名")
nickname: Optional[str] = Field("", description="姓名")
UserList = List[UserRead]