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)) {