调整部分代码结构

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

@@ -38,7 +38,7 @@ namespace OpenAuth.Mvc
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
//注册app层
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (LoginApp)));
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (UserManagerApp)));
//注册领域服务
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(AuthoriseService)))

View File

@@ -1,21 +1,15 @@
// ***********************************************************************
// Assembly : OpenAuth.Mvc
// Author : Administrator
// Created : 09-22-2015
// Author : yubaolee
// Created : 07-11-2016
//
// Last Modified By : Administrator
// Last Modified On : 09-22-2015
// ***********************************************************************
// <copyright file="BaseController.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// 基础控制器
// 继承该控制器可以防止未登录查看
// 继承该控制器后如果想访问控制器中存在但模块配置里面没有的ActionHome/Git请使用AnonymousAttribute
// </summary>
// Last Modified By : yubaolee
// Last Modified On : 07-19-2016
// Contact : www.cnblogs.com/yubaolee
// File: BaseController.cs
// ***********************************************************************
using OpenAuth.Mvc.Models;
using System;
using System.Configuration;
@@ -23,11 +17,15 @@ using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using OpenAuth.App;
using OpenAuth.App.SSO;
namespace OpenAuth.Mvc.Controllers
{
/// <summary>
/// 基础控制器
/// <para>用于控制登录用户是否有权限访问指定的Action</para>
/// <para>李玉宝新增于2016-07-19 11:12:09</para>
/// </summary>
public class BaseController : SSOController
{
protected BjuiResponse BjuiResponse = new BjuiResponse();
@@ -36,8 +34,8 @@ namespace OpenAuth.Mvc.Controllers
{
base.OnActionExecuting(filterContext);
var loginUser = AutofacExt.GetFromFac<LoginApp>().GetLoginUser();
if (!AuthUtil.CheckLogin()) return;
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
var actionname = filterContext.ActionDescriptor.ActionName.ToLower();
@@ -46,8 +44,8 @@ namespace OpenAuth.Mvc.Controllers
throw new Exception("未能找到Action");
var authorize = function.GetCustomAttribute(typeof(AuthenticateAttribute));
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
//当前登录用户没有Action记录&&Action有anonymous标识
var module = AuthUtil.GetCurrentUser().Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
//当前登录用户没有Action记录&&Action有authenticate标识
if (authorize != null && module == null)
{
filterContext.Result = new RedirectResult("/Login/Index");

View File

@@ -1,6 +1,7 @@
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
using OpenAuth.App.SSO;
using OpenAuth.App.ViewModel;
using OpenAuth.Mvc.Models;
@@ -17,7 +18,7 @@ namespace OpenAuth.Mvc.Controllers
public ActionResult Index()
{
var user = AutofacExt.GetFromFac<LoginApp>().GetLoginUser();
var user = AuthUtil.GetCurrentUser();
return View(user.Modules);
}

View File

@@ -4,6 +4,7 @@ using OpenAuth.Domain;
using System;
using System.Linq;
using System.Web.Mvc;
using OpenAuth.App.SSO;
using OpenAuth.App.ViewModel;
using OpenAuth.Mvc.Models;
@@ -45,13 +46,13 @@ namespace OpenAuth.Mvc.Controllers
/// </summary>
public string LoadForTree()
{
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().Modules;
var orgs = AuthUtil.GetCurrentUser().Modules;
return JsonHelper.Instance.Serialize(orgs);
}
public string LoadModuleWithRoot()
{
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().Modules.MapToList<ModuleView>();
var orgs = AuthUtil.GetCurrentUser().Modules.MapToList<ModuleView>();
return JsonHelper.Instance.Serialize(orgs);
}

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using OpenAuth.App.SSO;
using OpenAuth.App.ViewModel;
namespace OpenAuth.Mvc.Controllers
@@ -35,7 +36,7 @@ namespace OpenAuth.Mvc.Controllers
public string LoadOrg()
{
return JsonHelper.Instance.Serialize(AutofacExt.GetFromFac<LoginApp>().GetLoginUser().AccessedOrgs);
return JsonHelper.Instance.Serialize(AuthUtil.GetCurrentUser().AccessedOrgs);
}
public string LoadForUser(int firstId)