mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-08-23 13:06:48 +08:00
调整部分代码结构
This commit is contained in:
parent
d66fd4b25e
commit
3dea7d00f0
@ -63,6 +63,11 @@ namespace Infrastructure
|
|||||||
{
|
{
|
||||||
right = Expression.Constant(filterObj.Value.Equals("1"));
|
right = Expression.Constant(filterObj.Value.Equals("1"));
|
||||||
}
|
}
|
||||||
|
else if (property.PropertyType == typeof(Guid?))
|
||||||
|
{
|
||||||
|
left = Expression.Property(left, "Value");
|
||||||
|
right = Expression.Constant(Guid.Parse(filterObj.Value));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception("暂不能解析该Key的类型");
|
throw new Exception("暂不能解析该Key的类型");
|
||||||
|
@ -1,49 +1,41 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using Infrastructure;
|
||||||
using Infrastructure;
|
using OpenAuth.App.ViewModel;
|
||||||
using OpenAuth.App.ViewModel;
|
using OpenAuth.Domain.Service;
|
||||||
using OpenAuth.App.SSO;
|
|
||||||
using OpenAuth.Domain.Service;
|
namespace OpenAuth.App
|
||||||
|
{
|
||||||
namespace OpenAuth.App
|
/// <summary>
|
||||||
{
|
/// 加载用户所有可访问的资源/机构/模块
|
||||||
public class LoginApp
|
/// <para>李玉宝新增于2016-07-19 10:53:30</para>
|
||||||
{
|
/// </summary>
|
||||||
private AuthoriseService _service;
|
public class AuthorizeApp
|
||||||
|
{
|
||||||
public LoginApp(AuthoriseService service)
|
private readonly AuthoriseService _service;
|
||||||
{
|
|
||||||
_service = service;
|
public AuthorizeApp(AuthoriseService service)
|
||||||
}
|
{
|
||||||
|
_service = service;
|
||||||
public LoginUserVM GetLoginUser()
|
}
|
||||||
{
|
|
||||||
if (!AuthUtil.CheckLogin())
|
public UserWithAccessedCtrls GetAccessedControls(string username)
|
||||||
{
|
{
|
||||||
throw new HttpException(401,"未登录");
|
_service.LoadAuthControls(username);
|
||||||
}
|
var user = new UserWithAccessedCtrls
|
||||||
|
{
|
||||||
return AuthUtil.GetCurrentUser();
|
User = _service.User,
|
||||||
}
|
AccessedOrgs = _service.Orgs,
|
||||||
|
Modules = _service.Modules.MapToList<ModuleView>(),
|
||||||
public LoginUserVM GetLoginUser(string username)
|
Resources = _service.Resources,
|
||||||
{
|
};
|
||||||
_service.GetUserAccessed(username);
|
|
||||||
var user = new LoginUserVM
|
foreach (var moduleView in user.Modules)
|
||||||
{
|
{
|
||||||
User = _service.User,
|
moduleView.Elements =
|
||||||
AccessedOrgs = _service.Orgs,
|
_service.ModuleElements.Where(u => u.ModuleId == moduleView.Id).OrderBy(u => u.Sort).ToList();
|
||||||
Modules = _service.Modules.MapToList<ModuleView>(),
|
}
|
||||||
Resources = _service.Resources,
|
|
||||||
};
|
return user;
|
||||||
|
}
|
||||||
foreach (var moduleView in user.Modules)
|
}
|
||||||
{
|
|
||||||
moduleView.Elements =
|
|
||||||
_service.ModuleElements.Where(u => u.ModuleId == moduleView.Id).OrderBy(u => u.Sort).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -73,7 +73,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CategoryManagerApp.cs" />
|
<Compile Include="CategoryManagerApp.cs" />
|
||||||
<Compile Include="LoginApp.cs" />
|
<Compile Include="AuthorizeApp.cs" />
|
||||||
<Compile Include="ModuleElementManagerApp.cs" />
|
<Compile Include="ModuleElementManagerApp.cs" />
|
||||||
<Compile Include="ModuleManagerApp.cs" />
|
<Compile Include="ModuleManagerApp.cs" />
|
||||||
<Compile Include="ResourceManagerApp.cs" />
|
<Compile Include="ResourceManagerApp.cs" />
|
||||||
@ -94,7 +94,7 @@
|
|||||||
<Compile Include="UserManagerApp.cs" />
|
<Compile Include="UserManagerApp.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="OrgManagerApp.cs" />
|
<Compile Include="OrgManagerApp.cs" />
|
||||||
<Compile Include="ViewModel\LoginUserVM.cs" />
|
<Compile Include="ViewModel\UserWithAccessedCtrls.cs" />
|
||||||
<Compile Include="ViewModel\ModuleElementVM.cs" />
|
<Compile Include="ViewModel\ModuleElementVM.cs" />
|
||||||
<Compile Include="ViewModel\ModuleView.cs" />
|
<Compile Include="ViewModel\ModuleView.cs" />
|
||||||
<Compile Include="ViewModel\RoleVM.cs" />
|
<Compile Include="ViewModel\RoleVM.cs" />
|
||||||
|
@ -74,14 +74,14 @@ namespace OpenAuth.App.SSO
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="remark">The remark.</param>
|
/// <param name="remark">The remark.</param>
|
||||||
/// <returns>LoginUserVM.</returns>
|
/// <returns>LoginUserVM.</returns>
|
||||||
public static LoginUserVM GetCurrentUser(string remark = "")
|
public static UserWithAccessedCtrls GetCurrentUser(string remark = "")
|
||||||
{
|
{
|
||||||
|
|
||||||
var requestUri = String.Format("/SSO/Check/GetUser?token={0}&requestid={1}", GetToken(), remark);
|
var requestUri = String.Format("/SSO/Check/GetUser?token={0}&requestid={1}", GetToken(), remark);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var value = _helper.Get<LoginUserVM>(null, requestUri);
|
var value = _helper.Get<UserWithAccessedCtrls>(null, requestUri);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -39,7 +39,7 @@ namespace OpenAuth.App.SSO
|
|||||||
if (string.IsNullOrEmpty(token))
|
if (string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
//直接登录
|
//直接登录
|
||||||
filterContext.Result = SsoLoginResult(cookieSessionUserName);
|
filterContext.Result = LoginResult(cookieSessionUserName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -47,14 +47,14 @@ namespace OpenAuth.App.SSO
|
|||||||
if (AuthUtil.CheckLogin(token, request.RawUrl) == false)
|
if (AuthUtil.CheckLogin(token, request.RawUrl) == false)
|
||||||
{
|
{
|
||||||
//会话丢失,跳转到登录页面
|
//会话丢失,跳转到登录页面
|
||||||
filterContext.Result = SsoLoginResult(cookieSessionUserName);
|
filterContext.Result = LoginResult(cookieSessionUserName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnActionExecuting(filterContext);
|
base.OnActionExecuting(filterContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ActionResult SsoLoginResult(string username)
|
private static ActionResult LoginResult(string username)
|
||||||
{
|
{
|
||||||
//跳转到SSO站点登陆
|
//跳转到SSO站点登陆
|
||||||
//return new RedirectResult(string.Format("{0}/sso/login?appkey={1}&username={2}",
|
//return new RedirectResult(string.Format("{0}/sso/login?appkey={1}&username={2}",
|
||||||
|
@ -57,7 +57,8 @@ namespace OpenAuth.App.SSO
|
|||||||
if (string.IsNullOrEmpty(token))
|
if (string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
//直接登录
|
//直接登录
|
||||||
filterContext.Result = SsoLoginResult(cookieSessionUserName);
|
filterContext.Result = LoginResult(cookieSessionUserName);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -65,14 +66,15 @@ namespace OpenAuth.App.SSO
|
|||||||
if (AuthUtil.CheckLogin(token, request.RawUrl) == false)
|
if (AuthUtil.CheckLogin(token, request.RawUrl) == false)
|
||||||
{
|
{
|
||||||
//会话丢失,跳转到登录页面
|
//会话丢失,跳转到登录页面
|
||||||
filterContext.Result = SsoLoginResult(cookieSessionUserName);
|
filterContext.Result = LoginResult(cookieSessionUserName);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnActionExecuting(filterContext);
|
base.OnActionExecuting(filterContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ActionResult SsoLoginResult(string username)
|
private static ActionResult LoginResult(string username)
|
||||||
{
|
{
|
||||||
//跳转到SSO站点登陆
|
//跳转到SSO站点登陆
|
||||||
//return new RedirectResult(string.Format("{0}/sso/login?appkey={1}&username={2}",
|
//return new RedirectResult(string.Format("{0}/sso/login?appkey={1}&username={2}",
|
||||||
|
@ -1,45 +1,47 @@
|
|||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
// Assembly : OpenAuth.App
|
// Assembly : OpenAuth.App
|
||||||
// Author : Yubao Li
|
// Author : Yubao Li
|
||||||
// Created : 12-01-2015
|
// Created : 12-01-2015
|
||||||
//
|
//
|
||||||
// Last Modified By : Yubao Li
|
// Last Modified By : Yubao Li
|
||||||
// Last Modified On : 12-01-2015
|
// Last Modified On : 12-01-2015
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
// <copyright file="LoginUserVM.cs" company="">
|
// <copyright file="LoginUserVM.cs" company="">
|
||||||
// Copyright (c) . All rights reserved.
|
// Copyright (c) . All rights reserved.
|
||||||
// </copyright>
|
// </copyright>
|
||||||
// <summary>登陆视图模型</summary>
|
// <summary>用户及权限视图模型</summary>
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenAuth.Domain;
|
using OpenAuth.Domain;
|
||||||
|
|
||||||
namespace OpenAuth.App.ViewModel
|
namespace OpenAuth.App.ViewModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 登陆用户视图模型
|
/// 视图模型
|
||||||
/// </summary>
|
/// <para>包括用户及用户可访问的机构/资源/模块</para>
|
||||||
public class LoginUserVM
|
/// <para>李玉宝修改于2016-07-19 10:57:31</para>
|
||||||
{
|
/// </summary>
|
||||||
public User User { get; set; }
|
public class UserWithAccessedCtrls
|
||||||
/// <summary>
|
{
|
||||||
/// 用户可以访问到的模块(包括所属角色与自己的所有模块)
|
public User User { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public List<ModuleView> Modules { get; set; }
|
/// 用户可以访问到的模块(包括所属角色与自己的所有模块)
|
||||||
|
/// </summary>
|
||||||
//用户可以访问的资源
|
public List<ModuleView> Modules { get; set; }
|
||||||
public List<Resource> Resources { get; set; }
|
|
||||||
|
//用户可以访问的资源
|
||||||
/// <summary>
|
public List<Resource> Resources { get; set; }
|
||||||
/// 用户所属机构
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public List<Org> Orgs { get; set; }
|
/// 用户所属机构
|
||||||
|
/// </summary>
|
||||||
/// <summary>
|
public List<Org> Orgs { get; set; }
|
||||||
/// 用户可访问的机构
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public IEnumerable<Org> AccessedOrgs { get; set; }
|
/// 用户可访问的机构
|
||||||
}
|
/// </summary>
|
||||||
|
public IEnumerable<Org> AccessedOrgs { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
@ -70,64 +70,83 @@ namespace OpenAuth.Domain.Service
|
|||||||
_user.CheckPassword(password);
|
_user.CheckPassword(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设置开发者账号
|
|
||||||
/// </summary>
|
|
||||||
public void SetSysUser()
|
|
||||||
{
|
|
||||||
_user = new User
|
|
||||||
{
|
|
||||||
Account = "System"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GetUserAccessed(string name)
|
/// <summary>
|
||||||
|
/// 加载用户可访问的所有机构/资源/菜单
|
||||||
|
/// <para>李玉宝于2016-07-19 10:32:19</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
public void LoadAuthControls(string name)
|
||||||
{
|
{
|
||||||
if (name == "System")
|
if (name == "System")
|
||||||
{
|
{
|
||||||
_modules = _unitWork.Find<Module>(null).ToList();
|
_user = new User{Account = "System"};
|
||||||
_moduleElements = _unitWork.Find<ModuleElement>(null).ToList();
|
LoadForSystem();
|
||||||
|
|
||||||
_resources = _unitWork.Find<Resource>(null).OrderBy(u => u.SortNo).ToList();
|
|
||||||
|
|
||||||
_orgs = _unitWork.Find<Org>(null).OrderBy(u => u.SortNo).ToList();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_user = _unitWork.FindSingle<User>(u => u.Account == name);
|
_user = _unitWork.FindSingle<User>(u => u.Account == name);
|
||||||
//用户角色
|
if (_user != null)
|
||||||
var userRoleIds = _unitWork.Find<Relevance>(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
{
|
||||||
|
LoadForUser();
|
||||||
//用户角色与自己分配到的模块ID
|
}
|
||||||
var moduleIds = _unitWork.Find<Relevance>(
|
|
||||||
u =>
|
|
||||||
(u.FirstId == _user.Id && u.Key == "UserModule") ||
|
|
||||||
(u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
|
||||||
//得出最终用户拥有的模块
|
|
||||||
_modules = _unitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).ToList();
|
|
||||||
|
|
||||||
//用户角色与自己分配到的菜单ID
|
|
||||||
var elementIds = _unitWork.Find<Relevance>(
|
|
||||||
u =>
|
|
||||||
(u.FirstId == _user.Id && u.Key == "UserElement") ||
|
|
||||||
(u.Key == "RoleElement" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
|
||||||
//模块菜单权限
|
|
||||||
_moduleElements = _unitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id)).ToList();
|
|
||||||
|
|
||||||
//用户角色与自己分配到的资源ID
|
|
||||||
var resourceIds = _unitWork.Find<Relevance>(
|
|
||||||
u =>
|
|
||||||
(u.FirstId == _user.Id && u.Key == "UserResource") ||
|
|
||||||
(u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
|
||||||
_resources = _unitWork.Find<Resource>(u => resourceIds.Contains(u.Id)).ToList();
|
|
||||||
|
|
||||||
//用户角色与自己分配到的机构ID
|
|
||||||
var orgids = _unitWork.Find<Relevance>(
|
|
||||||
u =>
|
|
||||||
(u.FirstId == _user.Id && u.Key == "UserAccessedOrg") ||
|
|
||||||
(u.Key == "RoleAccessedOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
|
||||||
_orgs = _unitWork.Find<Org>(u => orgids.Contains(u.Id)).ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载用户权限
|
||||||
|
/// <para>李玉宝于2016-07-19 10:20:16</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
private void LoadForUser()
|
||||||
|
{
|
||||||
|
//用户角色
|
||||||
|
var userRoleIds =
|
||||||
|
_unitWork.Find<Relevance>(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
||||||
|
|
||||||
|
//用户角色与自己分配到的模块ID
|
||||||
|
var moduleIds = _unitWork.Find<Relevance>(
|
||||||
|
u =>
|
||||||
|
(u.FirstId == _user.Id && u.Key == "UserModule") ||
|
||||||
|
(u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||||
|
//得出最终用户拥有的模块
|
||||||
|
_modules = _unitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).ToList();
|
||||||
|
|
||||||
|
//用户角色与自己分配到的菜单ID
|
||||||
|
var elementIds = _unitWork.Find<Relevance>(
|
||||||
|
u =>
|
||||||
|
(u.FirstId == _user.Id && u.Key == "UserElement") ||
|
||||||
|
(u.Key == "RoleElement" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||||
|
//模块菜单权限
|
||||||
|
_moduleElements = _unitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id)).ToList();
|
||||||
|
|
||||||
|
//用户角色与自己分配到的资源ID
|
||||||
|
var resourceIds = _unitWork.Find<Relevance>(
|
||||||
|
u =>
|
||||||
|
(u.FirstId == _user.Id && u.Key == "UserResource") ||
|
||||||
|
(u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||||
|
_resources = _unitWork.Find<Resource>(u => resourceIds.Contains(u.Id)).ToList();
|
||||||
|
|
||||||
|
//用户角色与自己分配到的机构ID
|
||||||
|
var orgids = _unitWork.Find<Relevance>(
|
||||||
|
u =>
|
||||||
|
(u.FirstId == _user.Id && u.Key == "UserAccessedOrg") ||
|
||||||
|
(u.Key == "RoleAccessedOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||||
|
_orgs = _unitWork.Find<Org>(u => orgids.Contains(u.Id)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载系统管理员权限
|
||||||
|
/// <para>李玉宝于2016-07-19 10:19:31</para>
|
||||||
|
/// </summary>
|
||||||
|
private void LoadForSystem()
|
||||||
|
{
|
||||||
|
_modules = _unitWork.Find<Module>(null).ToList();
|
||||||
|
_moduleElements = _unitWork.Find<ModuleElement>(null).ToList();
|
||||||
|
|
||||||
|
_resources = _unitWork.Find<Resource>(null).OrderBy(u => u.SortNo).ToList();
|
||||||
|
|
||||||
|
_orgs = _unitWork.Find<Org>(null).OrderBy(u => u.SortNo).ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -47,7 +47,7 @@ namespace OpenAuth.Domain.Service
|
|||||||
|
|
||||||
public IEnumerable<ModuleElement> LoadByModuleId(string loginuser, int id)
|
public IEnumerable<ModuleElement> LoadByModuleId(string loginuser, int id)
|
||||||
{
|
{
|
||||||
_authoriseService.GetUserAccessed(loginuser);
|
_authoriseService.LoadAuthControls(loginuser);
|
||||||
if (_authoriseService.ModuleElements.Count == 0) //用户没有任何资源
|
if (_authoriseService.ModuleElements.Count == 0) //用户没有任何资源
|
||||||
{
|
{
|
||||||
return new List<ModuleElement>();
|
return new List<ModuleElement>();
|
||||||
@ -70,7 +70,7 @@ namespace OpenAuth.Domain.Service
|
|||||||
public List<dynamic> LoadWithAccess(string username, string accessType, int firstId, int moduleId)
|
public List<dynamic> LoadWithAccess(string username, string accessType, int firstId, int moduleId)
|
||||||
{
|
{
|
||||||
var listVms = new List<dynamic>();
|
var listVms = new List<dynamic>();
|
||||||
_authoriseService.GetUserAccessed(username);
|
_authoriseService.LoadAuthControls(username);
|
||||||
if (_authoriseService.ModuleElements.Count == 0) //用户没有任何资源
|
if (_authoriseService.ModuleElements.Count == 0) //用户没有任何资源
|
||||||
{
|
{
|
||||||
return listVms;
|
return listVms;
|
||||||
|
@ -40,7 +40,7 @@ namespace OpenAuth.Domain.Service
|
|||||||
public dynamic Load(string loginuser, int parentId, int pageindex, int pagesize)
|
public dynamic Load(string loginuser, int parentId, int pageindex, int pagesize)
|
||||||
{
|
{
|
||||||
|
|
||||||
_authoriseService.GetUserAccessed(loginuser);
|
_authoriseService.LoadAuthControls(loginuser);
|
||||||
if (_authoriseService.Modules.Count == 0) //用户不能访问任何模块
|
if (_authoriseService.Modules.Count == 0) //用户不能访问任何模块
|
||||||
{
|
{
|
||||||
return new
|
return new
|
||||||
|
@ -48,7 +48,7 @@ namespace OpenAuth.Domain.Service
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public dynamic Load(string username, int categoryId, int pageindex, int pagesize)
|
public dynamic Load(string username, int categoryId, int pageindex, int pagesize)
|
||||||
{
|
{
|
||||||
_authoriseService.GetUserAccessed(username);
|
_authoriseService.LoadAuthControls(username);
|
||||||
if (_authoriseService.Resources.Count == 0) //用户没有任何资源
|
if (_authoriseService.Resources.Count == 0) //用户没有任何资源
|
||||||
{
|
{
|
||||||
return new
|
return new
|
||||||
@ -122,7 +122,7 @@ namespace OpenAuth.Domain.Service
|
|||||||
public List<dynamic> LoadWithAccess(string username, string accessType, int firstId, int cId)
|
public List<dynamic> LoadWithAccess(string username, string accessType, int firstId, int cId)
|
||||||
{
|
{
|
||||||
var listVms = new List<dynamic>();
|
var listVms = new List<dynamic>();
|
||||||
_authoriseService.GetUserAccessed(username);
|
_authoriseService.LoadAuthControls(username);
|
||||||
if (_authoriseService.Resources.Count == 0) //用户没有任何资源
|
if (_authoriseService.Resources.Count == 0) //用户没有任何资源
|
||||||
{
|
{
|
||||||
return listVms;
|
return listVms;
|
||||||
|
@ -29,7 +29,7 @@ namespace OpenAuth.Domain.Service
|
|||||||
public dynamic Load(string username, int orgId, int pageindex, int pagesize)
|
public dynamic Load(string username, int orgId, int pageindex, int pagesize)
|
||||||
{
|
{
|
||||||
|
|
||||||
_authoriseService.GetUserAccessed(username);
|
_authoriseService.LoadAuthControls(username);
|
||||||
if (_authoriseService.Orgs.Count == 0) //用户没有任何可见机构
|
if (_authoriseService.Orgs.Count == 0) //用户没有任何可见机构
|
||||||
{
|
{
|
||||||
return new
|
return new
|
||||||
|
@ -38,7 +38,7 @@ namespace OpenAuth.Mvc
|
|||||||
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
|
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
|
||||||
|
|
||||||
//注册app层
|
//注册app层
|
||||||
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (LoginApp)));
|
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (UserManagerApp)));
|
||||||
|
|
||||||
//注册领域服务
|
//注册领域服务
|
||||||
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(AuthoriseService)))
|
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(AuthoriseService)))
|
||||||
|
@ -1,21 +1,15 @@
|
|||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
// Assembly : OpenAuth.Mvc
|
// Assembly : OpenAuth.Mvc
|
||||||
// Author : Administrator
|
// Author : yubaolee
|
||||||
// Created : 09-22-2015
|
// Created : 07-11-2016
|
||||||
//
|
//
|
||||||
// Last Modified By : Administrator
|
// Last Modified By : yubaolee
|
||||||
// Last Modified On : 09-22-2015
|
// Last Modified On : 07-19-2016
|
||||||
// ***********************************************************************
|
// Contact : www.cnblogs.com/yubaolee
|
||||||
// <copyright file="BaseController.cs" company="">
|
// File: BaseController.cs
|
||||||
// Copyright (c) . All rights reserved.
|
|
||||||
// </copyright>
|
|
||||||
// <summary>
|
|
||||||
// 基础控制器
|
|
||||||
// 继承该控制器可以防止未登录查看
|
|
||||||
// 继承该控制器后,如果想访问控制器中存在,但模块配置里面没有的Action(如:Home/Git),请使用AnonymousAttribute
|
|
||||||
// </summary>
|
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
|
|
||||||
using OpenAuth.Mvc.Models;
|
using OpenAuth.Mvc.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
@ -23,11 +17,15 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using OpenAuth.App;
|
|
||||||
using OpenAuth.App.SSO;
|
using OpenAuth.App.SSO;
|
||||||
|
|
||||||
namespace OpenAuth.Mvc.Controllers
|
namespace OpenAuth.Mvc.Controllers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 基础控制器
|
||||||
|
/// <para>用于控制登录用户是否有权限访问指定的Action</para>
|
||||||
|
/// <para>李玉宝新增于2016-07-19 11:12:09</para>
|
||||||
|
/// </summary>
|
||||||
public class BaseController : SSOController
|
public class BaseController : SSOController
|
||||||
{
|
{
|
||||||
protected BjuiResponse BjuiResponse = new BjuiResponse();
|
protected BjuiResponse BjuiResponse = new BjuiResponse();
|
||||||
@ -36,8 +34,8 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
{
|
{
|
||||||
base.OnActionExecuting(filterContext);
|
base.OnActionExecuting(filterContext);
|
||||||
|
|
||||||
var loginUser = AutofacExt.GetFromFac<LoginApp>().GetLoginUser();
|
if (!AuthUtil.CheckLogin()) return;
|
||||||
|
|
||||||
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
||||||
var actionname = filterContext.ActionDescriptor.ActionName.ToLower();
|
var actionname = filterContext.ActionDescriptor.ActionName.ToLower();
|
||||||
|
|
||||||
@ -46,8 +44,8 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
throw new Exception("未能找到Action");
|
throw new Exception("未能找到Action");
|
||||||
|
|
||||||
var authorize = function.GetCustomAttribute(typeof(AuthenticateAttribute));
|
var authorize = function.GetCustomAttribute(typeof(AuthenticateAttribute));
|
||||||
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
var module = AuthUtil.GetCurrentUser().Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
||||||
//当前登录用户没有Action记录&&Action没有anonymous标识
|
//当前登录用户没有Action记录&&Action有authenticate标识
|
||||||
if (authorize != null && module == null)
|
if (authorize != null && module == null)
|
||||||
{
|
{
|
||||||
filterContext.Result = new RedirectResult("/Login/Index");
|
filterContext.Result = new RedirectResult("/Login/Index");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using OpenAuth.App;
|
using OpenAuth.App;
|
||||||
|
using OpenAuth.App.SSO;
|
||||||
using OpenAuth.App.ViewModel;
|
using OpenAuth.App.ViewModel;
|
||||||
using OpenAuth.Mvc.Models;
|
using OpenAuth.Mvc.Models;
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
|
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
var user = AutofacExt.GetFromFac<LoginApp>().GetLoginUser();
|
var user = AuthUtil.GetCurrentUser();
|
||||||
return View(user.Modules);
|
return View(user.Modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ using OpenAuth.Domain;
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using OpenAuth.App.SSO;
|
||||||
using OpenAuth.App.ViewModel;
|
using OpenAuth.App.ViewModel;
|
||||||
using OpenAuth.Mvc.Models;
|
using OpenAuth.Mvc.Models;
|
||||||
|
|
||||||
@ -45,13 +46,13 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string LoadForTree()
|
public string LoadForTree()
|
||||||
{
|
{
|
||||||
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().Modules;
|
var orgs = AuthUtil.GetCurrentUser().Modules;
|
||||||
return JsonHelper.Instance.Serialize(orgs);
|
return JsonHelper.Instance.Serialize(orgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string LoadModuleWithRoot()
|
public string LoadModuleWithRoot()
|
||||||
{
|
{
|
||||||
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().Modules.MapToList<ModuleView>();
|
var orgs = AuthUtil.GetCurrentUser().Modules.MapToList<ModuleView>();
|
||||||
return JsonHelper.Instance.Serialize(orgs);
|
return JsonHelper.Instance.Serialize(orgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using OpenAuth.App.SSO;
|
||||||
using OpenAuth.App.ViewModel;
|
using OpenAuth.App.ViewModel;
|
||||||
|
|
||||||
namespace OpenAuth.Mvc.Controllers
|
namespace OpenAuth.Mvc.Controllers
|
||||||
@ -35,7 +36,7 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
|
|
||||||
public string LoadOrg()
|
public string LoadOrg()
|
||||||
{
|
{
|
||||||
return JsonHelper.Instance.Serialize(AutofacExt.GetFromFac<LoginApp>().GetLoginUser().AccessedOrgs);
|
return JsonHelper.Instance.Serialize(AuthUtil.GetCurrentUser().AccessedOrgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string LoadForUser(int firstId)
|
public string LoadForUser(int firstId)
|
||||||
|
@ -15,7 +15,7 @@ namespace OpenAuth.UnitTest
|
|||||||
public void TestMethod1()
|
public void TestMethod1()
|
||||||
{
|
{
|
||||||
AuthoriseService _service = new AuthoriseService(new UnitWork() );
|
AuthoriseService _service = new AuthoriseService(new UnitWork() );
|
||||||
_service.GetUserAccessed("test");
|
_service.LoadAuthControls("test");
|
||||||
|
|
||||||
var orgs = _service.Orgs;
|
var orgs = _service.Orgs;
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@ namespace OpenAuth.WebApi.Areas.SSO.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class CheckController : Controller
|
public class CheckController : Controller
|
||||||
{
|
{
|
||||||
private LoginApp _app;
|
private AuthorizeApp _app;
|
||||||
public CheckController()
|
public CheckController()
|
||||||
{
|
{
|
||||||
_app = AutofacExt.GetFromFac<LoginApp>();
|
_app = AutofacExt.GetFromFac<AuthorizeApp>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetStatus(string token = "", string requestid = "")
|
public bool GetStatus(string token = "", string requestid = "")
|
||||||
@ -44,7 +44,7 @@ namespace OpenAuth.WebApi.Areas.SSO.Controllers
|
|||||||
string userName = GetUserName(token, requestid);
|
string userName = GetUserName(token, requestid);
|
||||||
if (!string.IsNullOrEmpty(userName))
|
if (!string.IsNullOrEmpty(userName))
|
||||||
{
|
{
|
||||||
return JsonHelper.Instance.Serialize(_app.GetLoginUser(userName));
|
return JsonHelper.Instance.Serialize(_app.GetAccessedControls(userName));
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
@ -38,7 +38,7 @@ namespace OpenAuth.WebApi
|
|||||||
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
|
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
|
||||||
|
|
||||||
//注册app层
|
//注册app层
|
||||||
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (LoginApp)));
|
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (AuthorizeApp)));
|
||||||
|
|
||||||
//注册领域服务
|
//注册领域服务
|
||||||
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(AuthoriseService)))
|
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(AuthoriseService)))
|
||||||
|
Loading…
Reference in New Issue
Block a user