OpenAuth.Net/OpenAuth.Mvc/Controllers/BaseController.cs

54 lines
1.9 KiB
C#
Raw Normal View History

2016-01-05 10:03:35 +08:00
// ***********************************************************************
2015-09-22 23:10:00 +08:00
// 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;
2015-12-01 17:30:24 +08:00
using OpenAuth.App.ViewModel;
2015-09-23 00:10:11 +08:00
using OpenAuth.Mvc.Models;
2015-12-04 00:14:55 +08:00
using System.Linq;
2015-12-02 10:06:30 +08:00
using System.Web.Mvc;
2015-09-22 23:10:00 +08:00
namespace OpenAuth.Mvc.Controllers
{
2015-12-02 10:06:30 +08:00
public class BaseController : Controller
{
2015-11-08 23:19:04 +08:00
protected BjuiResponse BjuiResponse = new BjuiResponse();
2015-12-02 10:06:30 +08:00
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var loginUser = SessionHelper.GetSessionUser<LoginUserVM>();
if (loginUser == null)
2015-12-01 17:30:24 +08:00
{
2015-12-02 16:28:01 +08:00
filterContext.Result = new RedirectResult("/Login/Index");
2015-12-02 10:06:30 +08:00
return;
}
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
2015-12-02 10:06:30 +08:00
if (controllername != "home") //主页控制器无需权限控制
2015-12-02 10:06:30 +08:00
{
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
2015-12-04 00:14:55 +08:00
if (module == null)
{
filterContext.Result = new RedirectResult("/Login/Index");
return;
}
else
{
ViewBag.Module = module; //为View显示服务主要是为了显示按钮
2015-12-04 00:14:55 +08:00
}
2015-12-01 17:30:24 +08:00
}
2015-12-02 10:06:30 +08:00
base.OnActionExecuting(filterContext);
}
}
2015-09-22 23:10:00 +08:00
}