mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-05-10 15:48:01 +08:00

1 完成进出库实例Stock; 2 全面实现组织数据分离,参考Stock实例; 3 全新的基于CodeSmith EF生成机制; 4 全面完成菜单授权; 5 增加Anonymous机制,可以灵活控制Action是否需要权限控制;
63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
// ***********************************************************************
|
||
// Assembly : OpenAuth.Mvc
|
||
// Author : Administrator
|
||
// Created : 09-22-2015
|
||
//
|
||
// Last Modified By : Administrator
|
||
// Last Modified On : 09-22-2015
|
||
// ***********************************************************************
|
||
// <copyright file="BaseController.cs" company="">
|
||
// Copyright (c) . All rights reserved.
|
||
// </copyright>
|
||
// <summary>基础控制器,设置权限</summary>
|
||
// ***********************************************************************
|
||
|
||
using Infrastructure.Helper;
|
||
using OpenAuth.App.ViewModel;
|
||
using OpenAuth.Mvc.Models;
|
||
using System;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using System.Web.Mvc;
|
||
|
||
namespace OpenAuth.Mvc.Controllers
|
||
{
|
||
public class BaseController : Controller
|
||
{
|
||
protected BjuiResponse BjuiResponse = new BjuiResponse();
|
||
|
||
protected override void OnActionExecuting(ActionExecutingContext filterContext)
|
||
{
|
||
var loginUser = SessionHelper.GetSessionUser<LoginUserVM>();
|
||
if (loginUser == null)
|
||
{
|
||
filterContext.Result = new RedirectResult("/Login/Index");
|
||
return;
|
||
}
|
||
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
||
|
||
if (controllername != "home") //主页控制器无需权限控制
|
||
{
|
||
var actionname = Request.RequestContext.RouteData.Values["action"].ToString();
|
||
var function = this.GetType().GetMethods().FirstOrDefault(u => u.Name == actionname);
|
||
if (function == null)
|
||
throw new Exception("未能找到Action");
|
||
|
||
var anonymous = function.GetCustomAttribute(typeof(AnonymousAttribute));
|
||
|
||
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
||
if (module == null && anonymous == null)
|
||
{
|
||
filterContext.Result = new RedirectResult("/Login/Index");
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
ViewBag.Module = module; //为View显示服务,主要是为了显示按钮
|
||
}
|
||
}
|
||
|
||
base.OnActionExecuting(filterContext);
|
||
}
|
||
}
|
||
} |