增加后台前端页面判断按钮权限
This commit is contained in:
@@ -408,7 +408,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
|||||||
//执行添加管理员
|
//执行添加管理员
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[MyAuthorize("add", "admins", "JSON")]
|
[MyAuthorize("add", "admins", "JSON")]
|
||||||
public IActionResult AddAdmin(FormCollection fc)
|
public IActionResult AddAdmin(IFormCollection fc)
|
||||||
{
|
{
|
||||||
string userName = fc["UserName"];
|
string userName = fc["UserName"];
|
||||||
string newPwd = fc["PassWord"];
|
string newPwd = fc["PassWord"];
|
||||||
@@ -487,7 +487,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
|||||||
//执行编辑管理员
|
//执行编辑管理员
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[MyAuthorize("edit", "admins", "JSON")]
|
[MyAuthorize("edit", "admins", "JSON")]
|
||||||
public IActionResult EditAdmin(FormCollection fc)
|
public IActionResult EditAdmin(IFormCollection fc)
|
||||||
{
|
{
|
||||||
string userName = fc["UserName"];
|
string userName = fc["UserName"];
|
||||||
string newPwd = fc["PassWord"];
|
string newPwd = fc["PassWord"];
|
||||||
|
|||||||
@@ -35,15 +35,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="toolbar" class="btn-group">
|
<div id="toolbar" class="btn-group">
|
||||||
<button id="btn_add" type="button" class="btn btn-outline btn-default" onclick="top.showDialog('addarticle','添加文章','/AdminCP/Article/AddArticle',0,0)">
|
@if (AdminUtils.CheckAdminPower("add", "article"))
|
||||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
|
{
|
||||||
</button>
|
<button id="btn_add" type="button" class="btn btn-outline btn-default" onclick="top.showDialog('addarticle','添加文章','/AdminCP/Article/AddArticle',0,0)">
|
||||||
@*<button id="btn_edit" type="button" class="btn btn-outline btn-default">
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
|
|
||||||
</button>
|
</button>
|
||||||
<button id="btn_delete" type="button" class="btn btn-outline btn-default">
|
}
|
||||||
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
|
|
||||||
</button>*@
|
@*<button id="btn_edit" type="button" class="btn btn-outline btn-default">
|
||||||
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
|
||||||
|
</button>
|
||||||
|
<button id="btn_delete" type="button" class="btn btn-outline btn-default">
|
||||||
|
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
|
||||||
|
</button>*@
|
||||||
</div>
|
</div>
|
||||||
<table id="tb_departments"></table>
|
<table id="tb_departments"></table>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
@using COMCMS.Web
|
@using COMCMS.Web
|
||||||
@using COMCMS.Core
|
@using COMCMS.Core
|
||||||
@using COMCMS.Common
|
@using COMCMS.Common
|
||||||
|
@using COMCMS.Web.Common
|
||||||
@using XCode
|
@using XCode
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
@@ -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 检查管理员有没有管理权限
|
||||||
|
/// <summary>
|
||||||
|
/// 检查管理员有没有管理权限
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="eventKey">动作,如add、edit</param>
|
||||||
|
/// <param name="menuKey">菜单名称,如article、product</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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<AdminMenuEvent> listevents = JsonConvert.DeserializeObject<IList<AdminMenuEvent>>(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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ namespace COMCMS.Web.Common
|
|||||||
if (!string.IsNullOrEmpty(my.Roles.Powers))
|
if (!string.IsNullOrEmpty(my.Roles.Powers))
|
||||||
{
|
{
|
||||||
IList<AdminMenuEvent> listevents = JsonConvert.DeserializeObject<IList<AdminMenuEvent>>(my.Roles.Powers);
|
IList<AdminMenuEvent> listevents = JsonConvert.DeserializeObject<IList<AdminMenuEvent>>(my.Roles.Powers);
|
||||||
if (listevents != null && listevents.Count <= 0)
|
if (listevents != null && listevents.Count > 0)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(_menuKey) && !string.IsNullOrEmpty(_eventKey))
|
if (!string.IsNullOrEmpty(_menuKey) && !string.IsNullOrEmpty(_eventKey))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user