protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
        {
            var loginUserInfo = WebUserHelp.GetNowLoginUser();

            loginUserInfo.NowCityId = WebUserHelp.GetNowCityId();
            return(loginUserInfo);
        }
Beispiel #2
0
        //在执行操作方法之前由 MVC 框架调用
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            int         errorType  = 0;
            string      message    = "";
            RequestType rType      = NowRequestType;
            bool        checkLogin = IsCheckLogin;

            if (checkLogin)
            {
                //是否通过身份验证
                if (!WebUserHelp.CheckUser(filterContext, AndNowFunctionCodes, OrNowFunctionCodes, NowFunctionPageUrl, out errorType, out message))
                {
                    //登陆超时
                    if (errorType == WebUserHelp.NotLogin)
                    {
                        if (rType == RequestType.ACTION)//同步页面请求
                        {
                            filterContext.Result = WebUserHelp.GetActionLoginPage();
                        }
                        else if (rType == RequestType.OPEN)//弹出窗口请求
                        {
                            filterContext.Result = WebUserHelp.GetActionLoginPageOpen();
                        }
                        else//ajax页面请求
                        {
                            filterContext.Result = new Ajax_JsonFormatResult_NotLogin();
                        }
                    }
                    else if (errorType == WebUserHelp.NotRight) //无权限
                    {
                        if (rType == RequestType.ACTION)        //同步页面请求
                        {
                            filterContext.Result = WebUserHelp.GetActionNotRightPage();
                        }
                        else//ajax页面请求
                        {
                            filterContext.Result = new Ajax_JsonFormatResult_NotRight();
                        }
                    }
                }
                ////是否通过身份验证
                //if (!filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
                //{ }
                //if (session["user"] == null)
                //{
                //    filterContext.Result = new RedirectResult("~/Login/index");
                //}
            }
            base.OnActionExecuting(filterContext);
        }
Beispiel #3
0
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            int         errorType  = 0;
            RequestType rType      = NowRequestType;
            bool        checkLogin = IsCheckLogin;

            if (checkLogin)
            {
                //验证登录
                var user = WebUserHelp.GetNowLoginUser();
                if (user != null)
                {
                    //验证权限
                    if ((
                            (AndNowFunctionCodes != null && AndNowFunctionCodes.Length > 0) || (OrNowFunctionCodes != null && OrNowFunctionCodes.Length > 0)
                            ) &&
                        !string.IsNullOrEmpty(NowFunctionPageUrl))
                    {
                        //if (WebUserHelp.CheckNowPageFunctionCode(NowFunctionPageUrl, AndNowFunctionCodes, OrNowFunctionCodes))
                        //{
                        user.NowCityId = WebUserHelp.GetNowCityId();
                        List <int> intList = new List <int>();
                        var        list    = _functionService.GetAllBy(user.UserName, user.FxtCompanyId, user.NowCityId, NowFunctionPageUrl).ToList();
                        if (AndNowFunctionCodes != null && list.Where(obj => AndNowFunctionCodes.Contains(obj.FunctionCode)).Count() < AndNowFunctionCodes.Length)
                        {
                            errorType = WebUserHelp.NotRight;
                        }

                        if (OrNowFunctionCodes != null && list.Where(obj => OrNowFunctionCodes.Contains(obj.FunctionCode)).Count() < 1)
                        {
                            errorType = WebUserHelp.NotRight;
                        }
                        //}
                    }
                }
                else
                {
                    log.Info("登陆失败");
                    errorType = WebUserHelp.NotLogin;
                }

                //是否通过身份验证
                if (errorType != 0)
                {
                    //登陆超时
                    if (errorType == WebUserHelp.NotLogin)
                    {
                        if (rType == RequestType.ACTION)//同步页面请求
                        {
                            filterContext.Result = WebUserHelp.GetActionLoginPage();
                        }
                        else if (rType == RequestType.OPEN)//弹出窗口请求
                        {
                            filterContext.Result = WebUserHelp.GetActionLoginPageOpen();
                        }
                        else//ajax页面请求
                        {
                            filterContext.Result = new NJsonResult(new AjaxResult()
                            {
                                Result  = true,
                                Code    = "301",
                                Message = "登陆超时"
                            });
                        }
                    }
                    else if (errorType == WebUserHelp.NotRight) //无权限
                    {
                        if (rType == RequestType.ACTION)        //同步页面请求
                        {
                            filterContext.Result = WebUserHelp.GetActionNotRightPage();
                        }
                        else if (rType == RequestType.OPEN)
                        {
                            filterContext.Result = new ContentResult()
                            {
                                Content = "无权限"
                            };
                        }
                        else//ajax页面请求
                        {
                            filterContext.Result = new Ajax_JsonFormatResult_NotRight();
                        }
                    }
                }
                ////是否通过身份验证
                //if (!filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
                //{ }
                //if (session["user"] == null)
                //{
                //    filterContext.Result = new RedirectResult("~/Login/index");
                //}
            }
            //base.OnActionExecuting(filterContext);
        }