mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2025-08-26 13:26:04 +08:00

* Update and fix permissions logic * feat: Update base route * Exclude non-system routing record operation logs * Update the parameter variable name * Fix the jwt authorization verify * Roles menu authorization is turned off by default * Fix the operation log code field type * Update the casbin routing string to config * Fix JWT middleware * Add custom msg of token error * Add the character length of the operation log code field * Update the logout interface authorization
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Query
|
|
|
|
from backend.app.common.casbin_rbac import DependsRBAC
|
|
from backend.app.common.pagination import paging_data, PageDepends
|
|
from backend.app.common.response.response_schema import response_base
|
|
from backend.app.database.db_mysql import CurrentSession
|
|
from backend.app.schemas.login_log import GetAllLoginLog
|
|
from backend.app.services.login_log_service import LoginLogService
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get('', summary='(模糊条件)分页获取登录日志', dependencies=[DependsRBAC, PageDepends])
|
|
async def get_all_login_logs(
|
|
db: CurrentSession,
|
|
username: Annotated[str | None, Query()] = None,
|
|
status: Annotated[bool | None, Query()] = None,
|
|
ip: Annotated[str | None, Query()] = None,
|
|
):
|
|
log_select = await LoginLogService.get_select(username=username, status=status, ip=ip)
|
|
page_data = await paging_data(db, log_select, GetAllLoginLog)
|
|
return await response_base.success(data=page_data)
|
|
|
|
|
|
@router.delete('', summary='(批量)删除登录日志', dependencies=[DependsRBAC])
|
|
async def delete_login_log(pk: Annotated[list[int], Query(...)]):
|
|
count = await LoginLogService.delete(pk=pk)
|
|
if count > 0:
|
|
return await response_base.success()
|
|
return await response_base.fail()
|
|
|
|
|
|
@router.delete('/all', summary='清空登录日志', dependencies=[DependsRBAC])
|
|
async def delete_all_login_logs():
|
|
count = await LoginLogService.delete_all()
|
|
if count > 0:
|
|
return await response_base.success()
|
|
return await response_base.fail()
|