From fa160cac8312199a8120975a567e3ad69ffbd29e Mon Sep 17 00:00:00 2001
From: Ling0925 <2449858657a@gmail.com>
Date: Wed, 13 Nov 2024 16:23:30 +0800
Subject: [PATCH] =?UTF-8?q?105040=20=E7=94=A8=E6=88=B7=E6=9D=83=E9=99=90?=
=?UTF-8?q?=E9=A1=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
LFlow.Base/Base.xml | 1 +
LFlow.Permission/PermissionMiddleware.cs | 53 +++++++++++--------
.../Service/IPermissionService.cs | 38 ++++++++++++-
LFlow.Permission/Service/PermissionService.cs | 5 ++
.../Service/UserManagementService.cs | 4 +-
LFlow.UserManagement/UserMiddleware.cs | 46 ++++++++++++----
LFlow.UserManagement/Util/PasswordHelper.cs | 8 +++
7 files changed, 118 insertions(+), 37 deletions(-)
diff --git a/LFlow.Base/Base.xml b/LFlow.Base/Base.xml
index a65d9c5..87a4ee5 100644
--- a/LFlow.Base/Base.xml
+++ b/LFlow.Base/Base.xml
@@ -238,6 +238,7 @@
入口
+
diff --git a/LFlow.Permission/PermissionMiddleware.cs b/LFlow.Permission/PermissionMiddleware.cs
index fa21d74..6e74960 100644
--- a/LFlow.Permission/PermissionMiddleware.cs
+++ b/LFlow.Permission/PermissionMiddleware.cs
@@ -1,6 +1,7 @@
using System.Net.Sockets;
using LFlow.Base;
using LFlow.Base.Utils;
+using LFlow.Cache.Interface;
using LFlow.Middleware;
using LFlow.Permission.Service;
using Microsoft.AspNetCore.Http;
@@ -12,7 +13,7 @@ namespace LFlow.Permission;
///
/// 权限中间件
///
-public class PermissionMiddleware : ILFlowMiddleware
+public class PermissionMiddleware(ISelfCache selfCache ) : ILFlowMiddleware
{
///
/// 优先级
@@ -28,28 +29,34 @@ public class PermissionMiddleware : ILFlowMiddleware
///
public async Task RunAsync(HttpContext context, Func next)
{
- var progName = context.GetRouteData()?.Values["controller"]?.ToString();
- var progAction = context.GetRouteData()?.Values["action"]?.ToString();
- if (progName != null)
- {
- var service = App.GetService();
- var progPermission = service != null ? await service.GetProgPerminssionListAsync(progName) : null;
- var currentPermission = progPermission?.FirstOrDefault(p => p.PermissionAction == progAction);
- if (currentPermission == null || currentPermission!.IsPublic)
- {
- await next();
- }
- else
- {
- //TODO 从缓存中根据Token获取用户信息,并判断是否有权限
- await context.Response.WriteAsync(JsonConvert.SerializeObject(ApiResult