2016-01-05 17:14:10 +08:00
|
|
|
|
// ***********************************************************************
|
2015-09-22 23:10:00 +08:00
|
|
|
|
// Assembly : OpenAuth.Mvc
|
2016-07-19 11:44:48 +08:00
|
|
|
|
// Author : yubaolee
|
|
|
|
|
// Created : 07-11-2016
|
2015-09-22 23:10:00 +08:00
|
|
|
|
//
|
2016-07-19 11:44:48 +08:00
|
|
|
|
// Last Modified By : yubaolee
|
|
|
|
|
// Last Modified On : 07-19-2016
|
|
|
|
|
// Contact : www.cnblogs.com/yubaolee
|
|
|
|
|
// File: BaseController.cs
|
2015-09-22 23:10:00 +08:00
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
2016-07-19 11:44:48 +08:00
|
|
|
|
|
2015-09-23 00:10:11 +08:00
|
|
|
|
using OpenAuth.Mvc.Models;
|
2016-01-08 12:53:48 +08:00
|
|
|
|
using System;
|
2016-10-14 11:22:16 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-04-25 11:53:21 +08:00
|
|
|
|
using System.Configuration;
|
2015-12-04 00:14:55 +08:00
|
|
|
|
using System.Linq;
|
2016-01-08 12:53:48 +08:00
|
|
|
|
using System.Reflection;
|
2016-04-25 11:53:21 +08:00
|
|
|
|
using System.Web;
|
2015-12-02 10:06:30 +08:00
|
|
|
|
using System.Web.Mvc;
|
2016-10-14 11:22:16 +08:00
|
|
|
|
using Infrastructure;
|
2017-11-30 17:47:41 +08:00
|
|
|
|
using OpenAuth.App.Response;
|
2016-07-08 18:51:48 +08:00
|
|
|
|
using OpenAuth.App.SSO;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
2016-07-19 11:44:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 基础控制器
|
|
|
|
|
/// <para>用于控制登录用户是否有权限访问指定的Action</para>
|
|
|
|
|
/// <para>李玉宝新增于2016-07-19 11:12:09</para>
|
|
|
|
|
/// </summary>
|
2016-07-08 18:51:48 +08:00
|
|
|
|
public class BaseController : SSOController
|
2015-12-02 10:06:30 +08:00
|
|
|
|
{
|
2016-10-14 11:22:16 +08:00
|
|
|
|
protected Response Result = new Response();
|
|
|
|
|
protected ModuleView CurrentModule;
|
2016-10-24 17:16:16 +08:00
|
|
|
|
protected string Controllername; //当前控制器小写名称
|
|
|
|
|
protected string Actionname; //当前Action小写名称
|
2015-11-08 23:19:04 +08:00
|
|
|
|
|
2015-12-02 10:06:30 +08:00
|
|
|
|
protected override void OnActionExecuting(ActionExecutingContext filterContext)
|
|
|
|
|
{
|
2016-07-08 18:51:48 +08:00
|
|
|
|
base.OnActionExecuting(filterContext);
|
|
|
|
|
|
2016-09-08 16:20:31 +08:00
|
|
|
|
if (!AuthUtil.CheckLogin()) return;
|
2016-07-19 11:44:48 +08:00
|
|
|
|
|
2016-10-24 17:16:16 +08:00
|
|
|
|
Controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
|
|
|
|
Actionname = filterContext.ActionDescriptor.ActionName.ToLower();
|
2016-01-17 11:29:46 +08:00
|
|
|
|
|
2016-10-24 17:16:16 +08:00
|
|
|
|
var function = this.GetType().GetMethods().FirstOrDefault(u => u.Name.ToLower() == Actionname);
|
2016-01-14 17:30:29 +08:00
|
|
|
|
if (function == null)
|
|
|
|
|
throw new Exception("未能找到Action");
|
2015-12-02 10:06:30 +08:00
|
|
|
|
|
2016-05-26 20:10:22 +08:00
|
|
|
|
var authorize = function.GetCustomAttribute(typeof(AuthenticateAttribute));
|
2016-10-24 17:16:16 +08:00
|
|
|
|
CurrentModule = AuthUtil.GetCurrentUser().Modules.FirstOrDefault(u => u.Url.ToLower().Contains(Controllername));
|
2016-07-19 11:44:48 +08:00
|
|
|
|
//当前登录用户没有Action记录&&Action有authenticate标识
|
2016-10-14 11:22:16 +08:00
|
|
|
|
if (authorize != null && CurrentModule == null)
|
2015-12-02 10:06:30 +08:00
|
|
|
|
{
|
2016-01-14 17:30:29 +08:00
|
|
|
|
filterContext.Result = new RedirectResult("/Login/Index");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-07 15:22:01 +08:00
|
|
|
|
|
2016-04-25 11:53:21 +08:00
|
|
|
|
var version = ConfigurationManager.AppSettings["version"];
|
2016-09-08 16:20:31 +08:00
|
|
|
|
if (version == "demo" && Request.HttpMethod == "POST")
|
2016-04-25 11:53:21 +08:00
|
|
|
|
{
|
2016-10-24 17:16:16 +08:00
|
|
|
|
throw new HttpException(400, "演示版本,不能进行该操作,当前模块:" + Controllername + "/" + Actionname);
|
2016-04-25 11:53:21 +08:00
|
|
|
|
}
|
2016-09-08 16:20:31 +08:00
|
|
|
|
|
2015-12-02 10:06:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-22 23:10:00 +08:00
|
|
|
|
}
|