mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2025-08-19 07:21:31 +08:00

* WIP: add rbac authorization * Perform pre-commit fixes * add rbac route whitelist * add init test data user role associations * Restore database table id naming to fix generic crud base * Add database section value uniqueness settings * Update the test directory to tests * Update route_name file name to health_check * Split user auth and user action interfaces * Fix conflict between merge and current branch * Add pymysql dependencies * Fix RBAC authentication method * Add the select serialisation tool * Fix missing return messages due to global exception handler slicing * Update the user interface with associated relationships * Add items to be completed * Perform pre-commit fixes * Add pre-made routers * Paging data return structure optimisation * Split user auth and user interface tests * Fix user register test data structure error * Fix duplicate named test classes
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from fastapi import APIRouter, Depends
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
|
|
from backend.app.common.jwt import DependsUser
|
|
from backend.app.common.response.response_schema import response_base
|
|
from backend.app.schemas.token import Token
|
|
from backend.app.schemas.user import Auth
|
|
from backend.app.services.user_service import UserService
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post('/swagger_login', summary='swagger 表单登录', description='form 格式登录,仅用于 swagger 文档调试接口')
|
|
async def swagger_user_login(form_data: OAuth2PasswordRequestForm = Depends()) -> Token:
|
|
token, user = await UserService.swagger_login(form_data)
|
|
return Token(access_token=token, user=user)
|
|
|
|
|
|
@router.post('/login', summary='用户登录', description='json 格式登录, 仅支持在第三方api工具调试接口, 例如: postman')
|
|
async def user_login(obj: Auth):
|
|
token, user = await UserService.login(obj)
|
|
# TODO: token 存储
|
|
data = Token(access_token=token, user=user)
|
|
return response_base.response_200(data=data)
|
|
|
|
|
|
@router.post('/logout', summary='用户登出', dependencies=[DependsUser])
|
|
async def user_logout():
|
|
# TODO: 加入 token 黑名单
|
|
return response_base.response_200()
|