예제 #1
0
        /// <summary>
        /// 获取已验证用户信息
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            var token = CookieHelper.GetCookieValue("Admin");

            if (!string.IsNullOrEmpty(token))
            {
                m_token = token;
                //没有系统缓存重新登录
                HTools.CacheObj obj = base.cacheService.Get(Constant.CacheKey.LoginAdminInfoCacheKey + "_" + token);
                if (obj != null && obj.value != null)
                {
                    if (obj.value is Newtonsoft.Json.Linq.JObject)
                    {
                        User user = obj.value.ParseJSON <User>();
                        this.LoginUser = user;
                    }
                    else
                    {
                        this.LoginUser = (User)obj.value;
                    }
                }
                else
                {
                    this.LoginUser = null;
                }
            }
        }
예제 #2
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            if (base.LoginUser == null)
            {
                filterContext.Result = new RedirectResult("/AdminLogin");
            }
            HTools.CacheObj obj = base.cacheService.Get(Constant.CacheKey.PowerConfigCacheKey);
            if (obj != null && obj.value != null)
            {
                if (obj.value is Newtonsoft.Json.Linq.JObject)
                {
                    PowerAdmin power = obj.value.ParseJSON <PowerAdmin>();
                    this.Power = power;
                }
                else
                {
                    this.Power = (PowerAdmin)obj.value;
                }
            }
            else
            {
                this.Power = null;
            }

            if (this.Power == null)
            {
                this.Power = powerConfigService.LoadConfig(Constant.PowerConfigPath);
                base.cacheService.Add(Constant.CacheKey.PowerConfigCacheKey,
                                      new HTools.CacheObj()
                {
                    value = this.Power, AbsoluteExpiration = new TimeSpan(1, 0, 0, 0)
                });
            }
            if (this.pathConfig == null)
            {
                this.pathConfig = pathConfigService.LoadConfig(Constant.PathConfigPath);
                base.cacheService.Add(Constant.CacheKey.PathConfigCacheKey,
                                      new HTools.CacheObj()
                {
                    value = this.pathConfig, AbsoluteExpiration = new TimeSpan(1, 0, 0, 0)
                });
            }
            if (this.pathConfig != null)
            {
                ViewData["_PathConfig"] = this.pathConfig;
            }
            if (base.LoginUser != null)
            {
                ViewData["_LoginUser"] = base.LoginUser;
            }
            if (this.Power != null)
            {
                ViewData["_Power"] = this.Power;
            }
        }