Beispiel #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //if (WebSiteConfig.Environment != "dev")
            //{
            //    return;
            //}

            if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
            {
                return;
            }

            //忽略POST请求,和ajax请求
            if (filterContext.HttpContext.Request.HttpMethod != "GET" || filterContext.HttpContext.Request.IsAjaxRequest())
            {
                return;
            }

            if (IsPinAdmin())
            {
                return;
            }

            #region 登陆校验
            Account account = GetLoginAccount();
            if (account == null)
            {
                filterContext.Result = new RedirectResult("/dzhome/login");
                filterContext.Result = new EmptyResult();
                return;
            }

            int appId = Context.GetRequestInt("appId", 0);
            appId = appId == 0 ? Context.GetRequestInt("aid", 0) : appId;

            XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, account.Id.ToString());
            if (xcx == null)
            {
                filterContext.Result = new RedirectResult("/dzhome/casetemplate");
                filterContext.Result = new EmptyResult();
                return;
            }
            #endregion

            int pageType = XcxAppAccountRelationBLL.SingleModel.GetXcxTemplateType(xcx.Id);
            if (!EnabelVersion.Contains(pageType))
            {
                //当前小程序版本没有接入子帐号管理
                return;
            }

            string route = GetControllerRoute(filterContext);

            AuthInfo authInfo = null;
            bool     isMaster = IsMasterAuth(account);
            if (isMaster)
            {
                //最高管理权限
                authInfo = AuthRoleBLL.SingleModel.GetAppMasterAuth(pageType: pageType, authName: account.LoginId, accessUrl: route);
            }
            else
            {
                //子帐号权限
                AuthRole role = GetAdminAuth();
                authInfo          = AuthRoleBLL.SingleModel.GetAppMenuByRole(role: role, pageType: pageType, accessUrl: route);
                authInfo.AuthName = account.LoginId;
            }
            if (authInfo != null)
            {
                filterContext.ActionParameters["authInfo"] = authInfo;
                filterContext.Controller.ViewBag.authInfo  = authInfo;
                filterContext.Controller.ViewBag.versionId = xcx.VersionId;
            }

            //判断当前小程序访问权限
            if (authInfo != null && authInfo.AuthAdmin != null && authInfo.AuthAdmin.AId != xcx.Id)
            {
                string url = XcxAppAccountRelationBLL.SingleModel.GetXcxTemplateType(authInfo.AuthAdmin.AId) == (int)TmpType.拼享惠 ?
                             $"/pin/main?Id={authInfo.AuthAdmin.AId}&appId={authInfo.AuthAdmin.AId}" :
                             $"/SubAccount/Welcome?appId={authInfo.AuthAdmin.AId}&pageType={pageType}";
                filterContext.Result = new RedirectResult(url);
                filterContext.Result = new EmptyResult();
                return;
            }

            //判断当前路由访问权限
            bool?hasAccess = authInfo?.CheckRouteAccess();
            if (hasAccess.HasValue && !hasAccess.Value)
            {
                //拒绝访问,跳回欢迎页(无权限)
                filterContext.Result = new RedirectResult($"/SubAccount/Welcome?appId={xcx.Id}&pageType={pageType}");
                filterContext.Result = new EmptyResult();
                return;
            }
            if (hasAccess.HasValue && hasAccess.Value)
            {
                //允许访问(有权限)
                return;
            }

            //无权限凭证
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.Result = new JsonResult {
                    Data = new Return_Msg {
                        code = "403", isok = false, Msg = "登陆授权过期"
                    }, JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                };
                filterContext.Result = new EmptyResult();
            }
            else
            {
                filterContext.Result = new RedirectResult($"/SubAccount/Login?appId={xcx.Id}");
                filterContext.Result = new EmptyResult();
            }
        }