同步操作将从 zero/WaitAdmin开源后台系统(Python版) 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# +----------------------------------------------------------------------# | WaitAdmin(fastapi)快速开发后台管理系统# +----------------------------------------------------------------------# | 欢迎阅读学习程序代码,建议反馈是我们前进的动力# | 程序完全开源可支持商用,允许去除界面版权信息# | gitee: https://gitee.com/wafts/waitadmin-python# | github: https://github.com/topwait/waitadmin-python# | 官方网站: https://www.waitadmin.cn# | WaitAdmin团队版权所有并拥有最终解释权# +----------------------------------------------------------------------# | Author: WaitAdmin Team <2474369941@qq.com># +----------------------------------------------------------------------from typing import List, Dictfrom fastapi import Depends, Requestfrom fastapi.security import HTTPBearer, HTTPAuthorizationCredentialsfrom exception import AppExceptionfrom config import get_settingsfrom common.enums.errors import ErrorEnumfrom apps.admin.cache.login_cache import LoginCachefrom apps.admin.config import AdminConfigfrom plugins.safe.driver import SecurityDriverobstruction: Dict[str, List[str]] = {"LoginInterceptor": AdminConfig.not_need_login,"PermsInterceptor": AdminConfig.not_need_perms}class LoginInterceptor:@staticmethodasync def handler(request: Request, bearer: HTTPAuthorizationCredentials = Depends(HTTPBearer())):endpoint: any = request.scope.get("endpoint", lambda: None)if endpoint.__module__ == "starlette.staticfiles":return Truetoken: str = bearer.credentialsstatus = await SecurityDriver.module("admin").check_login(token)if status == "invalid":raise AppException(msg="登录失效",code=ErrorEnum.TOKEN_VALID.code)elif status == "disable":raise AppException(msg="您账号已被禁用",code=ErrorEnum.TOKEN_VALID.code)elif status == "kick":raise AppException(msg="您已被踢下线喇",code=ErrorEnum.TOKEN_VALID.code)return Trueclass PermsInterceptor:@staticmethodasync def handler(request: Request):module: str = get_settings().ROUTER_ALIAS.get("admin", "admin")uri: str = request.url.path.replace(f"/{module}/", "").replace("/", ":")admin_id: int = request.state.admin_idrole_id: int = request.state.role_id# 免登录验证接口if uri in AdminConfig.not_need_login:return True# 免权限验证接口if uri in AdminConfig.not_need_perms or admin_id == 1:return True# 查询角色的权限perms: List[str] = await LoginCache.role_perms_get(role_id)if uri not in perms:raise AppException(msg=ErrorEnum.PERMISSIONS_ERROR.msg,code=ErrorEnum.PERMISSIONS_ERROR.code)return True
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。