jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
using HH.WMS.Common;
using HH.AutoBom.Core;
using HH.Redis;
using HH.Redis.ReisModel;
//using HH.WMS.WebUI.AppCode;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
 
namespace HH.WMS.WebUI
{
    public class MvcMenuFilter : ActionFilterAttribute
    {
        private bool _isEnable = true;
 
        public MvcMenuFilter()
        {
            _isEnable = true;
        }
 
        public MvcMenuFilter(bool IsEnable)
        {
            _isEnable = IsEnable;
        }
 
        #region 登录状态检测
        /// <summary>
        /// 登录状态检测
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //如果值为true 说明当前为已登录后的页面执行的方法
            if (_isEnable)
            {
                var loginer = FormsAuth.GetUserData<LoginerBase>();
                string userCode = loginer.UserCode;
                string appCode =Constants.appCode;
                //根据用户名+应用ID生成RedisKey
                string redisKey = HH.Redis.ReisModel.Encrypt.EncryptionDES(appCode + userCode);
                HashOperator hp = new HashOperator();
                try
                {
                    string value = hp.GetValueFromHash(HH.WMS.Common.Constants.user_HashId, redisKey);
                    //未获取到数据 跳转到登录
                    if (string.IsNullOrEmpty(value))
                    {
                        FormsAuth.SingOut();
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Login", action = "Index", area = string.Empty }));
                    }
                    else
                    {
                        //定义写入redis的数据对象
                        RedisUserEntity userEntity = Newtonsoft.Json.JsonConvert.DeserializeObject<RedisUserEntity>(value);
                        //如果Flag不一致  则退出登录
                        //if (userEntity.CN_S_FLAG != loginer.Flag)
                        //{
                        //    FormsAuth.SingOut();
                        //    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Login", action = "Index", area = string.Empty }));
                        //}
                        //else
                        //{
                        userEntity.CN_T_CREATE = DateTime.Now;
                        string redis_value = Newtonsoft.Json.JsonConvert.SerializeObject(userEntity);
                        hp.SetEntryInHash(HH.WMS.Common.Constants.user_HashId, redisKey, redis_value);
                        //}
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    hp.Dispose();
                }
            }
            base.OnActionExecuting(filterContext);
        }
        #endregion
    }
}