调整部分代码结构

This commit is contained in:
yubaolee
2016-07-19 11:44:48 +08:00
parent d66fd4b25e
commit 3dea7d00f0
20 changed files with 207 additions and 186 deletions

View File

@@ -1,49 +1,41 @@
using System.Linq;
using System.Web;
using Infrastructure;
using OpenAuth.App.ViewModel;
using OpenAuth.App.SSO;
using OpenAuth.Domain.Service;
namespace OpenAuth.App
{
public class LoginApp
{
private AuthoriseService _service;
public LoginApp(AuthoriseService service)
{
_service = service;
}
public LoginUserVM GetLoginUser()
{
if (!AuthUtil.CheckLogin())
{
throw new HttpException(401,"未登录");
}
return AuthUtil.GetCurrentUser();
}
public LoginUserVM GetLoginUser(string username)
{
_service.GetUserAccessed(username);
var user = new LoginUserVM
{
User = _service.User,
AccessedOrgs = _service.Orgs,
Modules = _service.Modules.MapToList<ModuleView>(),
Resources = _service.Resources,
};
foreach (var moduleView in user.Modules)
{
moduleView.Elements =
_service.ModuleElements.Where(u => u.ModuleId == moduleView.Id).OrderBy(u => u.Sort).ToList();
}
return user;
}
}
using System.Linq;
using Infrastructure;
using OpenAuth.App.ViewModel;
using OpenAuth.Domain.Service;
namespace OpenAuth.App
{
/// <summary>
/// 加载用户所有可访问的资源/机构/模块
/// <para>李玉宝新增于2016-07-19 10:53:30</para>
/// </summary>
public class AuthorizeApp
{
private readonly AuthoriseService _service;
public AuthorizeApp(AuthoriseService service)
{
_service = service;
}
public UserWithAccessedCtrls GetAccessedControls(string username)
{
_service.LoadAuthControls(username);
var user = new UserWithAccessedCtrls
{
User = _service.User,
AccessedOrgs = _service.Orgs,
Modules = _service.Modules.MapToList<ModuleView>(),
Resources = _service.Resources,
};
foreach (var moduleView in user.Modules)
{
moduleView.Elements =
_service.ModuleElements.Where(u => u.ModuleId == moduleView.Id).OrderBy(u => u.Sort).ToList();
}
return user;
}
}
}

View File

@@ -73,7 +73,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CategoryManagerApp.cs" />
<Compile Include="LoginApp.cs" />
<Compile Include="AuthorizeApp.cs" />
<Compile Include="ModuleElementManagerApp.cs" />
<Compile Include="ModuleManagerApp.cs" />
<Compile Include="ResourceManagerApp.cs" />
@@ -94,7 +94,7 @@
<Compile Include="UserManagerApp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="OrgManagerApp.cs" />
<Compile Include="ViewModel\LoginUserVM.cs" />
<Compile Include="ViewModel\UserWithAccessedCtrls.cs" />
<Compile Include="ViewModel\ModuleElementVM.cs" />
<Compile Include="ViewModel\ModuleView.cs" />
<Compile Include="ViewModel\RoleVM.cs" />

View File

@@ -74,14 +74,14 @@ namespace OpenAuth.App.SSO
/// </summary>
/// <param name="remark">The remark.</param>
/// <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);
try
{
var value = _helper.Get<LoginUserVM>(null, requestUri);
var value = _helper.Get<UserWithAccessedCtrls>(null, requestUri);
return value;
}
catch (Exception ex)

View File

@@ -39,7 +39,7 @@ namespace OpenAuth.App.SSO
if (string.IsNullOrEmpty(token))
{
//直接登录
filterContext.Result = SsoLoginResult(cookieSessionUserName);
filterContext.Result = LoginResult(cookieSessionUserName);
}
else
{
@@ -47,14 +47,14 @@ namespace OpenAuth.App.SSO
if (AuthUtil.CheckLogin(token, request.RawUrl) == false)
{
//会话丢失,跳转到登录页面
filterContext.Result = SsoLoginResult(cookieSessionUserName);
filterContext.Result = LoginResult(cookieSessionUserName);
}
}
base.OnActionExecuting(filterContext);
}
private static ActionResult SsoLoginResult(string username)
private static ActionResult LoginResult(string username)
{
//跳转到SSO站点登陆
//return new RedirectResult(string.Format("{0}/sso/login?appkey={1}&username={2}",

View File

@@ -57,7 +57,8 @@ namespace OpenAuth.App.SSO
if (string.IsNullOrEmpty(token))
{
//直接登录
filterContext.Result = SsoLoginResult(cookieSessionUserName);
filterContext.Result = LoginResult(cookieSessionUserName);
return;
}
else
{
@@ -65,14 +66,15 @@ namespace OpenAuth.App.SSO
if (AuthUtil.CheckLogin(token, request.RawUrl) == false)
{
//会话丢失,跳转到登录页面
filterContext.Result = SsoLoginResult(cookieSessionUserName);
filterContext.Result = LoginResult(cookieSessionUserName);
return;
}
}
base.OnActionExecuting(filterContext);
}
private static ActionResult SsoLoginResult(string username)
private static ActionResult LoginResult(string username)
{
//跳转到SSO站点登陆
//return new RedirectResult(string.Format("{0}/sso/login?appkey={1}&username={2}",

View File

@@ -1,45 +1,47 @@
// ***********************************************************************
// Assembly : OpenAuth.App
// Author : Yubao Li
// Created : 12-01-2015
//
// Last Modified By : Yubao Li
// Last Modified On : 12-01-2015
// ***********************************************************************
// <copyright file="LoginUserVM.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary>登陆视图模型</summary>
// ***********************************************************************
using System.Collections.Generic;
using OpenAuth.Domain;
namespace OpenAuth.App.ViewModel
{
/// <summary>
/// 登陆用户视图模型
/// </summary>
public class LoginUserVM
{
public User User { get; set; }
/// <summary>
/// 用户可以访问到的模块(包括所属角色与自己的所有模块)
/// </summary>
public List<ModuleView> Modules { get; set; }
//用户可以访问的资源
public List<Resource> Resources { get; set; }
/// <summary>
/// 用户所属机构
/// </summary>
public List<Org> Orgs { get; set; }
/// <summary>
/// 用户可访问的机构
/// </summary>
public IEnumerable<Org> AccessedOrgs { get; set; }
}
}
// ***********************************************************************
// Assembly : OpenAuth.App
// Author : Yubao Li
// Created : 12-01-2015
//
// Last Modified By : Yubao Li
// Last Modified On : 12-01-2015
// ***********************************************************************
// <copyright file="LoginUserVM.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary>用户及权限视图模型</summary>
// ***********************************************************************
using System.Collections.Generic;
using OpenAuth.Domain;
namespace OpenAuth.App.ViewModel
{
/// <summary>
/// 视图模型
/// <para>包括用户及用户可访问的机构/资源/模块</para>
/// <para>李玉宝修改于2016-07-19 10:57:31</para>
/// </summary>
public class UserWithAccessedCtrls
{
public User User { get; set; }
/// <summary>
/// 用户可以访问到的模块(包括所属角色与自己的所有模块)
/// </summary>
public List<ModuleView> Modules { get; set; }
//用户可以访问的资源
public List<Resource> Resources { get; set; }
/// <summary>
/// 用户所属机构
/// </summary>
public List<Org> Orgs { get; set; }
/// <summary>
/// 用户可访问的机构
/// </summary>
public IEnumerable<Org> AccessedOrgs { get; set; }
}
}