예제 #1
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            string controllerName = filterContext.RouteData.Values["controller"].ToString().ToLower();
            string actionName     = filterContext.RouteData.Values["action"].ToString().ToLower();
            string returnUrl      = "/" + controllerName + "/" + actionName + filterContext.RequestContext.HttpContext.Request.Url.Query;

            string userJson = CookieHelper.GetCookieValue("User");

            //Log.Default.Debug(userJson);
            if (!userJson.IsNullOrEmpty())
            {
                CUsers user = null;
                try
                {
                    user = JsonConvert.DeserializeObject <CUsers>(userJson);
                    FF_User hs_user = UsersBll.Instance.GetUserByAdmin(user.UserCode);
                    filterContext.Controller.ViewBag.User = hs_user;
                    DateTime now        = DateTime.Now;
                    string   SecretCode = hs_user.SecretCode;
                    filterContext.Controller.ViewBag.ConfusionStringToHTML = SignUtil.CreateConfusionStringToHTML(SecretCode, now);
                }
                catch (Exception ex)
                {
                    Log.Default.Error(ex);
                }
                if (user == null || UsersBll.Instance.IsUserCodeRepeat(user.UserCode) == false)
                {
                    SetContextResult(filterContext, returnUrl);
                    return;
                }
            }
            else
            {
                SetContextResult(filterContext, returnUrl);
                return;
            }
        }