From d2b0ea14a133521f2c13f82ce0bf1e94e3b7d524 Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Thu, 23 Aug 2018 16:06:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=8E=E5=8F=B0=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E9=A1=B5=E9=9D=A2=E5=88=A4=E6=96=AD=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminCP/Controllers/MemberController.cs | 4 +- .../AdminCP/Views/Article/ArticleList.cshtml | 20 ++++--- .../Areas/AdminCP/Views/_ViewImports.cshtml | 1 + COMCMS.Web/Common/AdminUtils.cs | 58 +++++++++++++++++++ COMCMS.Web/Common/MyAuthorizeAttribute.cs | 2 +- 5 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 COMCMS.Web/Common/AdminUtils.cs diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs index d36a15b..0440ad6 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs @@ -408,7 +408,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //执行添加管理员 [HttpPost] [MyAuthorize("add", "admins", "JSON")] - public IActionResult AddAdmin(FormCollection fc) + public IActionResult AddAdmin(IFormCollection fc) { string userName = fc["UserName"]; string newPwd = fc["PassWord"]; @@ -487,7 +487,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //执行编辑管理员 [HttpPost] [MyAuthorize("edit", "admins", "JSON")] - public IActionResult EditAdmin(FormCollection fc) + public IActionResult EditAdmin(IFormCollection fc) { string userName = fc["UserName"]; string newPwd = fc["PassWord"]; diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml index ceb95e2..9b67e96 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml @@ -35,15 +35,19 @@
- - @* - *@ + } + + @* + *@
diff --git a/COMCMS.Web/Areas/AdminCP/Views/_ViewImports.cshtml b/COMCMS.Web/Areas/AdminCP/Views/_ViewImports.cshtml index 70b3c27..148344f 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/_ViewImports.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/_ViewImports.cshtml @@ -1,5 +1,6 @@ @using COMCMS.Web @using COMCMS.Core @using COMCMS.Common +@using COMCMS.Web.Common @using XCode @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/COMCMS.Web/Common/AdminUtils.cs b/COMCMS.Web/Common/AdminUtils.cs new file mode 100644 index 0000000..ab7d5b1 --- /dev/null +++ b/COMCMS.Web/Common/AdminUtils.cs @@ -0,0 +1,58 @@ +using COMCMS.Core; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using COMCMS.Common; +using XCode; +using NewLife.Log; + +namespace COMCMS.Web.Common +{ + public class AdminUtils + { + #region 检查管理员有没有管理权限 + /// + /// 检查管理员有没有管理权限 + /// + /// 动作,如add、edit + /// 菜单名称,如article、product + /// + public static bool CheckAdminPower(string eventKey, string menuKey) + { + if (!Admin.IsAdminLogin()) + { + return false; + } + + //判断权限 + Admin my = Admin.GetMyInfo(); + if (my.Roles.IsSuperAdmin != 1) + { + //获取所有的菜单权限 + if (string.IsNullOrEmpty(my.Roles.Powers)) + return false; + IList listevents = JsonConvert.DeserializeObject>(my.Roles.Powers); + if (listevents == null || listevents.Count > 0) + { + return false; + } + if (!string.IsNullOrEmpty(menuKey) && !string.IsNullOrEmpty(eventKey)) + { + if (listevents.FirstOrDefault(s => s.EventKey == eventKey && s.MenuKey == menuKey) == null) + { + //获取用户信息 + Admin he = Admin.GetMyInfo(); + string path = MyHttpContext.Current.Request.Path; + XTrace.WriteLine($"管理员:{he.UserName}访问地址:{path}没有找到权限!EventKey:{eventKey};MenuKey:{menuKey}"); + return false; + } + } + } + return true; + } + #endregion + + } +} diff --git a/COMCMS.Web/Common/MyAuthorizeAttribute.cs b/COMCMS.Web/Common/MyAuthorizeAttribute.cs index 373e499..6198ed6 100644 --- a/COMCMS.Web/Common/MyAuthorizeAttribute.cs +++ b/COMCMS.Web/Common/MyAuthorizeAttribute.cs @@ -50,7 +50,7 @@ namespace COMCMS.Web.Common if (!string.IsNullOrEmpty(my.Roles.Powers)) { IList listevents = JsonConvert.DeserializeObject>(my.Roles.Powers); - if (listevents != null && listevents.Count <= 0) + if (listevents != null && listevents.Count > 0) { if (!string.IsNullOrEmpty(_menuKey) && !string.IsNullOrEmpty(_eventKey)) {