转移.net core 3.1,为.NET 5做准备

This commit is contained in:
ÂëÉñ
2020-10-22 14:59:36 +08:00
parent fd9bca23a7
commit a35d596237
1080 changed files with 175912 additions and 185681 deletions

View File

@@ -9,64 +9,25 @@
// File: BaseController.cs
// ***********************************************************************
using OpenAuth.Mvc.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App.Response;
using OpenAuth.App.SSO;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.Interface;
namespace OpenAuth.Mvc.Controllers
{
/// <summary>
/// 基础控制器
/// <para>用于控制登录用户是否有权限访问指定的Action</para>
/// <para>李玉宝新增于2016-07-19 11:12:09</para>
/// </summary>
public class BaseController : SSOController
public class BaseController : Controller
{
protected Response Result = new Response();
protected string Controllername; //当前控制器小写名称
protected string Actionname; //当前Action小写名称
protected IAuth _authUtil;
protected override void OnActionExecuting(ActionExecutingContext filterContext)
public BaseController(IAuth authUtil)
{
base.OnActionExecuting(filterContext);
if (!AuthUtil.CheckLogin()) return;
Controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
Actionname = filterContext.ActionDescriptor.ActionName.ToLower();
var function = this.GetType().GetMethods().FirstOrDefault(u => u.Name.ToLower() == Actionname);
if (function == null)
throw new Exception("未能找到Action");
//权限验证标识
var authorize = function.GetCustomAttribute(typeof(AuthenticateAttribute));
if (authorize == null)
{
return;
}
var currentModule = AuthUtil.GetCurrentUser().Modules.FirstOrDefault(u => u.Url.ToLower().Contains(Controllername));
//当前登录用户没有Action记录&&Action有authenticate标识
if ( currentModule == null)
{
filterContext.Result = new RedirectResult("/Login/Index");
return;
}
var version = ConfigurationManager.AppSettings["version"];
if (version == "demo" && Request.HttpMethod == "POST")
{
throw new HttpException(400, "演示版本,不能进行该操作,当前模块:" + Controllername + "/" + Actionname);
}
_authUtil = authUtil;
}
}
}