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 登录状态检测
///
/// 登录状态检测
///
///
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//如果值为true 说明当前为已登录后的页面执行的方法
if (_isEnable)
{
var loginer = FormsAuth.GetUserData();
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(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
}
}