feat: axios loading & message
This commit is contained in:
@@ -12,5 +12,5 @@ async def login(auth_data: LoginForm) -> Response[LoginResult]:
|
||||
user_obj = await get_user({"username": auth_data.username})
|
||||
if user_obj:
|
||||
if verify_password(auth_data.password, user_obj.password):
|
||||
return dict(id=user_obj.id, access_token=generate_token(user_obj.username))
|
||||
return Response(data=LoginResult(id=user_obj.id, token=generate_token(auth_data.username)))
|
||||
return Response(msg="账号或密码错误")
|
||||
|
@@ -1,16 +1,18 @@
|
||||
from core.resp import Response
|
||||
from core.router import Router
|
||||
from core.security import get_password_hash
|
||||
from dbhelper.user import get_user_info, get_users, insert_user
|
||||
from schemas.common import ListAll
|
||||
from schemas.user import UserAdd, UserInfo, UserList, UserQuery
|
||||
|
||||
user = Router(prefix="/users", tags=["用户管理"])
|
||||
user = Router(prefix="/user", tags=["用户管理"])
|
||||
|
||||
|
||||
@user.post("", summary="用户添加")
|
||||
async def user_add(data: UserAdd) -> Response[UserInfo]:
|
||||
roles = data.rids
|
||||
del data.rids
|
||||
user.password = get_password_hash(user.password)
|
||||
return await insert_user(data, roles)
|
||||
|
||||
|
||||
|
@@ -4,8 +4,9 @@ from tortoise import Tortoise
|
||||
async def init_orm():
|
||||
"""初始化orm"""
|
||||
await Tortoise.init(
|
||||
db_url="sqlite://mini.db", modules={"models": ["models"]}
|
||||
db_url="sqlite://mini.db", modules={"models": ["models"]},
|
||||
)
|
||||
await Tortoise.generate_schemas()
|
||||
|
||||
|
||||
async def close_orm():
|
||||
|
@@ -28,5 +28,5 @@ class Msg(enum.Enum):
|
||||
|
||||
class Response(GenericModel, Generic[T]):
|
||||
code: Status = Status.OK
|
||||
msg: Union[Msg, str] = Msg.OK
|
||||
data: Optional[T]
|
||||
msg: Union[Msg, str] = Msg.OK
|
||||
|
BIN
backend/mini.db
BIN
backend/mini.db
Binary file not shown.
BIN
backend/mini.db-shm
Normal file
BIN
backend/mini.db-shm
Normal file
Binary file not shown.
0
backend/mini.db-wal
Normal file
0
backend/mini.db-wal
Normal file
@@ -18,7 +18,7 @@ class LoginResult(BaseModel):
|
||||
"""登录响应模型"""
|
||||
|
||||
id: int = Field(..., description="用户ID")
|
||||
access_token: str = Field(..., description="token 串")
|
||||
token: str = Field(..., description="token 串")
|
||||
token_type: str = Field("Bearer", description="token 类型")
|
||||
|
||||
|
||||
|
@@ -7,7 +7,7 @@ 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)
|
||||
UserIn = pydantic_model_creator(UserModel, name="UserIn", exclude_readonly=True, exclude=("status",))
|
||||
|
||||
UserRole = pydantic_model_creator(UserRoleModel, name="UserRole", exclude_readonly=True)
|
||||
|
||||
|
Reference in New Issue
Block a user