BaseController.cs
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Hh.Mes.Common;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.SystemAuth;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Linq;
using System.Reflection;
namespace WebMvc
{
/// <summary>
/// 基础控制器
/// <para>用于控制登录用户是否有权限访问指定的Action</para>
/// </summary>
public class BaseController : SSOController
{
public Response Result = new Response();
protected string controllerName; //当前控制器小写名称
protected string actionName; //当前Action小写名称
/// <summary>
/// 上下文
/// </summary>
public HttpContext context;
public BaseController(IAuth authUtil) : base(authUtil)
{
}
/// <summary>
/// https://blog.csdn.net/mango_love/article/details/84992020
/// </summary>
/// <param name="filterContext"></param>
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
ActionBefore(filterContext);
actionName = filterContext.RouteData.Values["action"].ToString();
var function = ((TypeInfo)GetType()).DeclaredMethods.FirstOrDefault(u => u.Name == actionName);
if (function == null)
{
Log4NetHelper.Instance.Info("请检查模块设置URL设置是否正确、请注意大小写! "+ actionName);
throw new ArgumentNullException($"请检查模块设置URL设置是否正确、请注意大小写!"+ actionName);
}
//权限验证标识
var authorize = function.GetCustomAttribute(typeof(AuthenticateAttribute));
if (authorize == null) return;
controllerName = filterContext.RouteData.Values["controller"].ToString();
var currentModule = authStrategyContext?.Modules.FirstOrDefault(u => u.Url.Contains(controllerName));
//当前登录用户没有Action记录&&Action有authenticate标识
if (currentModule == null)
{
Log4NetHelper.Instance.Info("登入失效:BaseController【currentModule】为空 ");
filterContext.Result = new RedirectResult("/Login/Index");
return;
}
}
public void ResponseEnumJosn()
{
ViewBag.EnumYesNoState = typeof(EnumtIsWorkClothes).GetJsonEnum();
ViewBag.EnumAGVState = typeof(EnumAGVState).GetJsonEnum();
ViewBag.EnumOrderHeadStatus = typeof(EnumOrderHeadStatus).GetJsonEnum();
ViewBag.EnumOrderBodyStatus = typeof(EnumOrderBodyStatus).GetJsonEnum();
ViewBag.EnumWorkReportStatus = typeof(EnumWorkReportStatus).GetJsonEnum();
ViewBag.EnumAgvTaskType = typeof(EnumAgvTaskType).GetJsonEnum();
ViewBag.EnumLocationStatus = typeof(EnumLocationStatus).GetJsonEnum();
ViewBag.EnumLog = typeof(EnumLog).GetJsonEnum();
ViewBag.EnumLoadData = typeof(EnumLoadData).GetJsonEnum();
ViewBag.InventoryUseState = typeof(InventoryUseState).GetJsonEnum();
ViewBag.EnumCutPlanHeadStatus = typeof(EnumCutPlanHeadStatus).GetJsonEnum();
ViewBag.EnumCutPlanDetailStatus = typeof(EnumCutPlanDetailStatus).GetJsonEnum();
ViewBag.EnumWeldTechnologyEquipmentStatus = typeof(EnumWeldTechnologyEquipmentStatus).GetJsonEnum();
ViewBag.EnumPipeMaterial = typeof(EnumPipeMaterial).GetJsonEnum();
}
public string Serialize(dynamic response)
{
return JsonHelper.Instance.Serialize(response);
}
}
}