mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 02:29:24 +08:00
1、全面实现按登录用户动态加载按钮;
2、优化模块授权代码; 3、优化内部功能加载模块的权限控制,比如:拥有模块授权功能的用户给别人授权时,只能访问到自己拥有的模块;
This commit is contained in:
@@ -32,14 +32,11 @@ namespace OpenAuth.Mvc.Controllers
|
||||
filterContext.Result = new RedirectResult("/Login/Index");
|
||||
return;
|
||||
}
|
||||
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
||||
|
||||
string url = Request.Url.LocalPath;
|
||||
if (url != "/"
|
||||
&& !url.Contains("Main")
|
||||
&& !url.Contains("Error")
|
||||
&& !url.Contains("Git"))
|
||||
if (controllername != "home") //主页控制器无需权限控制
|
||||
{
|
||||
var module = loginUser.Modules.FirstOrDefault(u => url.Contains(u.Url));
|
||||
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
||||
if (module == null)
|
||||
{
|
||||
filterContext.Result = new RedirectResult("/Login/Index");
|
||||
@@ -47,9 +44,10 @@ namespace OpenAuth.Mvc.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewBag.Module = module;
|
||||
ViewBag.Module = module; //为View显示服务,主要是为了显示按钮
|
||||
}
|
||||
}
|
||||
|
||||
base.OnActionExecuting(filterContext);
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity.Validation;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
@@ -78,11 +79,55 @@ namespace OpenAuth.Mvc.Controllers
|
||||
ViewBag.RoleId = roleId;
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public string AssignForRole(int roleId, string menuIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ids = menuIds.Split(',').Select(id => int.Parse(id)).ToArray();
|
||||
_app.AssignForRole(roleId, ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_bjuiResponse.statusCode = "300";
|
||||
_bjuiResponse.message = e.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(_bjuiResponse);
|
||||
}
|
||||
|
||||
public string Load(int roleId, int orgId)
|
||||
public string LoadForRole(int roleId, int orgId)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.LoadWithAccess("RoleElement", roleId, orgId));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 为用户分配菜单
|
||||
|
||||
public ActionResult AssignForUser(int userId)
|
||||
{
|
||||
ViewBag.UserId = userId;
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public string AssignForUser(int userId, string menuIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ids = menuIds.Split(',').Select(id => int.Parse(id)).ToArray();
|
||||
_app.AssignForUser(userId, ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_bjuiResponse.statusCode = "300";
|
||||
_bjuiResponse.message = e.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(_bjuiResponse);
|
||||
}
|
||||
|
||||
public string LoadForUser(int userId, int orgId)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.LoadWithAccess("UserElement", userId, orgId));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -4,6 +4,8 @@ using OpenAuth.Domain;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure.Helper;
|
||||
using OpenAuth.App.ViewModel;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
@@ -50,7 +52,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public string LoadForTree()
|
||||
{
|
||||
var orgs = _app.LoadForTree();
|
||||
var orgs = SessionHelper.GetSessionUser<LoginUserVM>().Modules;
|
||||
//添加根节点
|
||||
orgs.Add(new Module
|
||||
{
|
||||
@@ -70,7 +72,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
Id = 0,
|
||||
ParentId = -1,
|
||||
Name = "已为用户分配的模块",
|
||||
Name = "用户可访问模块(包括角色所拥有的)",
|
||||
CascadeId = "0"
|
||||
});
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
|
Reference in New Issue
Block a user