2016-01-05 17:14:10 +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>
|
2016-01-14 17:30:29 +08:00
|
|
|
|
// <summary>
|
|
|
|
|
// 基础控制器
|
|
|
|
|
// 继承该控制器可以防止未登录查看
|
|
|
|
|
// 继承该控制器后,如果想访问控制器中存在,但模块配置里面没有的Action(如:Home/Git),请使用AnonymousAttribute
|
|
|
|
|
// </summary>
|
2015-09-22 23:10:00 +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-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-04-21 10:54:05 +08:00
|
|
|
|
using OpenAuth.App;
|
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)
|
|
|
|
|
{
|
2016-04-21 10:54:05 +08:00
|
|
|
|
var loginUser = AutofacExt.GetFromFac<LoginApp>().GetLoginUser();
|
|
|
|
|
if (!User.Identity.IsAuthenticated)
|
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;
|
|
|
|
|
}
|
2015-12-07 15:22:01 +08:00
|
|
|
|
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
2016-01-17 11:29:46 +08:00
|
|
|
|
var actionname = filterContext.ActionDescriptor.ActionName.ToLower();
|
|
|
|
|
|
|
|
|
|
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-01-14 17:30:29 +08:00
|
|
|
|
var anonymous = function.GetCustomAttribute(typeof(AnonymousAttribute));
|
|
|
|
|
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
|
|
|
|
//当前登录用户没有Action记录&&Action没有anonymous标识
|
|
|
|
|
if (module == null && anonymous == null)
|
2015-12-02 10:06:30 +08:00
|
|
|
|
{
|
2016-01-14 17:30:29 +08:00
|
|
|
|
filterContext.Result = new RedirectResult("/Login/Index");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Module = module; //为View显示服务,主要是为了显示按钮
|
2015-12-01 17:30:24 +08:00
|
|
|
|
}
|
2015-12-07 15:22:01 +08:00
|
|
|
|
|
2016-04-25 11:53:21 +08:00
|
|
|
|
var version = ConfigurationManager.AppSettings["version"];
|
|
|
|
|
if (version == "demo")
|
|
|
|
|
{
|
|
|
|
|
HttpPostAttribute hobbyAttr = (HttpPostAttribute)Attribute.GetCustomAttribute(function, typeof(HttpPostAttribute));
|
|
|
|
|
if (actionname.Contains("del") || hobbyAttr != null) //客户端提交数据
|
|
|
|
|
{
|
|
|
|
|
throw new HttpException(400, "演示版本,不能进行该操作,当前模块:" + controllername +"/" +actionname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-02 10:06:30 +08:00
|
|
|
|
base.OnActionExecuting(filterContext);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-22 23:10:00 +08:00
|
|
|
|
}
|