示例#1
0
        /// <summary>
        /// 权限验证 同时设置page Item集合
        /// </summary>
        /// <param name="functionCodes">所查询权限集合</param>
        /// <param name="mainCode">page实际权限</param>
        /// <returns></returns>
        public Dictionary <string, bool> CheckAuthorization(ActionExecutingContext filterContext, string[] functionCodes, string[] mainCode = null)
        {
            if (functionCodes == null || functionCodes.Length <= 0)
            {
                return(new Dictionary <string, bool>()
                {
                    { "ok", true }
                });
            }
            Dictionary <string, bool> dic         = new Dictionary <string, bool>();
            Pub_FunctionBLL           functionBLL = new Pub_FunctionBLL();
            var userCode = NBCZUser.UserCode;

            var context = filterContext.HttpContext;

            if (userCode == null)
            {
                context.Response.Write("<script>window.location.href='../Login/Index';</script>");
                context.Response.End();
                return(dic);
            }

            // dic = functionBLL.CheckUserAuth(userCode, functionCodes);

            dic = new Dictionary <string, bool>();
            var userFunctions = NBCZUser.UserFunctions;

            foreach (var code in functionCodes)
            {
                var isHaveCode = userFunctions.Exists(p => p.FunctionCode == code);
                dic.Add(code, isHaveCode);
            }

            if (dic != null)
            {
                if (mainCode == null || mainCode.Length <= 0)
                {
                    mainCode = new string[] { functionCodes.FirstOrDefault() };
                }

                bool auth = dic.Any(p => (mainCode.Contains(p.Key) && p.Value == true));//多个主权限一个符合即可
                //主权限没通过
                if (!auth)
                {
                    context.Response.Write("<script>window.location.href='../NoAuth.html';</script>");
                    context.Response.End();
                }
                SetAuthViewState(filterContext, dic);
            }

            return(dic);
        }
示例#2
0
        /// <summary>
        /// 绑定左边菜单
        /// </summary>
        private void BindLeftMenu()
        {
            var funs = new Pub_FunctionBLL().GetList("StopFlag=0 AND MenuFlag=1 ");

            var navHtml = new StringBuilder();
            var funs1   = funs.Where(p => string.IsNullOrEmpty(p.ParentCode) || p.ParentCode == "0");

            foreach (var item in funs1)
            {
                navHtml.AppendFormat("<div title='{0}'  data-options=\"iconCls:'fa fa-navicon'\">", item.FunctionChina);
                navHtml.Append(BindLeftMenuChild(funs, item));
                navHtml.AppendFormat("</div>");
            }
            ViewBag.NavHtml = navHtml;
            //throw new NotImplementedException();
        }
示例#3
0
        public static void WriteUser(string userName)
        {
            LoginAdmin admin   = new LoginAdmin();
            var        pubUser = new Pub_UserBLL().GetUserByUserName(userName);
            var        context = HttpContext.Current;

            if (pubUser != null)
            {
                admin.UserCode    = pubUser.UserCode;
                admin.UserName    = pubUser.UserName;
                admin.MobilePhone = pubUser.Tel;
                admin.DeptCode    = pubUser.DeptCode;

                string functionSql = string.Format(@"select functioncode from dbo.Pub_UserFunction WHERE UserCode='{0}'
                                                UNION SELECT functioncode FROM dbo.Pub_RoleFunction
                                                WHERE RoleCode in (SELECT RoleCode FROM Pub_UserRole AS pur WHERE UserCode='{0}')", pubUser.UserCode);

                var funs = new Pub_FunctionBLL().GetList("StopFlag=0 AND FunctionCode In (" + functionSql + ")");
                admin.UserFunctions = funs;
            }
            context.Session["Admin"] = admin;
        }