Exemplo n.º 1
0
        /// <summary>
        /// 检查是否需要登陆
        /// </summary>
        /// <param name="context"></param>
        private void CheckNeedLogin(HttpContext context)
        {
            List <BLLPermission.Model.ModuleFilterInfo> pathList = bllRedis.GetModuleFilterInfoList();

            pathList = pathList.Where(p => p.FilterType == "WXOAuth").ToList();
            if (pathList.Where(p =>
                               (currentPath.Equals(p.PagePath, StringComparison.OrdinalIgnoreCase) && p.MatchType.Equals("all")) ||
                               (currentPath.StartsWith(p.PagePath, StringComparison.OrdinalIgnoreCase) && p.MatchType.Equals("start")) ||
                               (currentPath.EndsWith(p.PagePath, StringComparison.OrdinalIgnoreCase) && p.MatchType.Equals("end")) ||
                               (currentPath.ToLower().Contains(p.PagePath.ToLower()) && p.MatchType.Equals("contains"))
                               ).Count() == 0)
            {
                return;//匹配
            }
            //if (pathList.Count == 0) return;

            if (!new BLLCommRelation().ExistRelation(ZentCloud.BLLJIMP.Enums.CommRelationType.WXAuthPageMustLogin, bllUser.WebsiteOwner, ""))
            {
                return;
            }
            string ngRoute = context.Request["ngroute"];//ng路由

            if (!string.IsNullOrWhiteSpace(ngRoute))
            {
                currentUrl = currentUrl + "#" + ngRoute;
            }
            ToLog("跳转到登录页");
            context.Response.Redirect(appLoginUrl + string.Format("?redirect=" + HttpUtility.UrlEncode(currentUrl)), true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 检查是否需要授权
        /// </summary>
        /// <param name="path"></param>
        /// <param name="matchModel"></param>
        /// <returns></returns>
        private bool CheckIsToWXOAuth(string path, out ModuleFilterInfo matchModel)
        {
            ToLog("进入检查是否需要授权");
            List <ModuleFilterInfo> pathList = new List <ModuleFilterInfo>();
            var sourcePathList = bllRedis.GetModuleFilterInfoList().Where(p => p.FilterType == "WXOAuth");

            foreach (var item in sourcePathList)
            {
                pathList.Add(new ModuleFilterInfo()
                {
                    FilterType        = item.FilterType,
                    PagePath          = item.PagePath,
                    FilterDescription = item.FilterDescription,
                    MatchType         = item.MatchType,
                    Ex1 = item.Ex1
                });
            }

            //try
            //{

            //    ToLog("开始从redis获取授权列表");

            //    //从redis读取数据,在修改的时候记得更新redis key
            //    pathList = RedisHelper.RedisHelper.Get<List<ModuleFilterInfo>>("WXModuleFilter");
            //    if (pathList == null) pathList = new List<ModuleFilterInfo>();

            //    ToLog("从redis读取授权数据:" + (pathList == null ? "null" : JsonConvert.SerializeObject(pathList)));

            //}
            //catch (Exception ex)
            //{
            //    ToLog(ex.ToString());
            //}

            //if (pathList.Count == 0)
            //{
            //    pathList = new BLL().GetList<ModuleFilterInfo>(" FilterType = 'WXOAuth' ");

            //    try
            //    {
            //        RedisHelper.RedisHelper.Set("WXModuleFilter", pathList);
            //    }
            //    catch (Exception ex)
            //    {
            //        ToLog(ex.ToString());
            //    }
            //}


            //ZentCloud.Common.DataCache.

            if (pathList.Count > 0)
            {
                //先进行全文匹配
                List <ModuleFilterInfo> searchResult = pathList.Where(p => p.PagePath.Equals(path, StringComparison.OrdinalIgnoreCase) && p.MatchType.Equals("all")).ToList();

                if (searchResult.Count > 0)
                {
                    matchModel = searchResult[0];
                    return(true);
                }

                //开头匹配
                searchResult = pathList.Where(p => path.StartsWith(p.PagePath, StringComparison.OrdinalIgnoreCase) && p.MatchType.Equals("start")).ToList();
                if (searchResult.Count > 0)
                {
                    matchModel = searchResult[0];
                    return(true);
                }

                //结尾匹配
                searchResult = pathList.Where(p => path.EndsWith(p.PagePath, StringComparison.OrdinalIgnoreCase) && p.MatchType.Equals("end")).ToList();
                if (searchResult.Count > 0)
                {
                    matchModel = searchResult[0];
                    return(true);
                }

                //包含匹配
                searchResult = pathList.Where(p => path.ToLower().Contains(p.PagePath.ToLower()) && p.MatchType.Equals("contains")).ToList();
                if (searchResult.Count > 0)
                {
                    matchModel = searchResult[0];
                    return(true);
                }
            }
            matchModel = null;
            return(false);
        }