Esempio n. 1
0
        public static string GetLeftMenuInfo(string firstNode)
        {
            DataTable   MenuInfo       = new DataTable();
            int         roldId         = ManagerHelper.GetCurrentManager().RoleId;
            ManagerInfo currentManager = ManagerHelper.GetCurrentManager();

            if (currentManager.UserName.ToString() != "yihui")
            {
                MenuInfo = AdminMenuHelper.GetCurrentRoleMenuInfo(roldId);
            }
            else
            {
                MenuInfo = AdminMenuHelper.GetAllAdminMenus();
            }
            string json = "";

            DataRow[] rows = MenuInfo.Select(string.Format("Layout like '{0}%'", firstNode));
            foreach (DataRow row in rows)
            {
                var url    = string.Empty;
                var layout = row["layout"].ToString();
                if (layout.Length <= 4 && currentManager.UserName != "yihui")//如果当前是一二级菜单,则获取权限内的第一个三级菜单地址
                {
                    url = ManagerHelper.GetFirstRoleUrl(roldId, layout);
                }
                else
                {
                    url = row["MIUrl"].ToString();
                }
                json += string.Format("DataID=\"{0}\",Title=\"{1}\",Link=\"{2}\",Layout=\"{3}\",IconLink=\"{4}\";", row["MIID"], row["MIName"], /*row["MIUrl"]*/ url, row["Layout"], row["IconLink"]);
            }
            return(json);
        }
Esempio n. 2
0
 private void BindData()
 {
     allMenus = AdminMenuHelper.GetAllAdminMenus();//获取所有菜单信息
     allMenuList.DataSource = allMenus;
     allMenuList.DataBind();
     allMenus.PrimaryKey   = new DataColumn[] { allMenus.Columns["MIID"] };
     ViewState["allMenus"] = allMenus;
 }
Esempio n. 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.IsPostBack)
     {
         roleId = Request.QueryString["roleId"];
         DataTable currentMenuIds = AdminMenuHelper.GetRoleMenusId(Convert.ToInt32(roleId));
         currentMenuIds.PrimaryKey   = new DataColumn[] { currentMenuIds.Columns["MRId"] };
         ViewState["currentMenuIds"] = currentMenuIds;
         ManagerInfo currentManager = ManagerHelper.GetCurrentManager();
     }
 }
Esempio n. 4
0
        public static string GetSelect()
        {
            string selectLayoutIds = AdminMenuHelper.GetRoleSelectLayoutIds(Convert.ToInt32(roleId));

            if (selectLayoutIds != null)
            {
                return(selectLayoutIds);
            }
            else
            {
                return("false");
            }
        }
Esempio n. 5
0
        public StartupViewModel PrepareStartupViewData()
        {
            var setupConfig        = SetupHelper.LoadSetup();
            var model              = new StartupViewModel();
            var moduleSiteMenuList = new List <SiteMenuItem>();

            model.Default     = setupConfig.StartupUrl;
            model.StartupType = setupConfig.StartupType;

            model.Pages      = new SelectList(_pageService.LoadAllActive(), "Slug", "Title", GetSlug(setupConfig.StartupUrl));
            model.Posts      = new SelectList(_postService.LoadAllByPostStatusAndDate(NccPost.NccPostStatus.Published, DateTime.Now), "Slug", "Title", GetSlug(setupConfig.StartupUrl));
            model.Categories = new SelectList(_categoryService.LoadAllActive(), "Slug", "Title", GetSlug(setupConfig.StartupUrl));
            AdminMenuHelper.ModulesSiteMenus().Select(x => x.Value).ToList().ForEach(x => moduleSiteMenuList.AddRange(x));
            model.ModuleSiteMenus = new SelectList(moduleSiteMenuList, "Url", "Url", setupConfig.StartupUrl);

            ViewBag.DefaultChecked  = "";
            ViewBag.PageChecked     = "";
            ViewBag.CategoryChecked = "";
            ViewBag.PostChecked     = "";
            ViewBag.ModuleChecked   = "";

            if (setupConfig.StartupType == StartupTypes.Page)
            {
                ViewBag.PageChecked = "checked";
            }
            else if (setupConfig.StartupType == StartupTypes.Post)
            {
                ViewBag.PostChecked = "checked";
            }
            else if (setupConfig.StartupType == StartupTypes.Category)
            {
                ViewBag.CategoryChecked = "checked";
            }
            else if (setupConfig.StartupType == StartupTypes.Module)
            {
                ViewBag.ModuleChecked = "checked";
            }
            else
            {
                ViewBag.DefaultChecked = "checked";
            }

            return(model);
        }
Esempio n. 6
0
        public static string GetZnodes()
        {
            //DataTable allMenus = AdminMenuHelper.GetAllAdminMenus();//获取所有菜单信息
            DataTable currentMenus = AdminMenuHelper.GetRoleMenuInfos();
            string    znodes       = string.Empty;

            if (currentMenus != null)//如果
            {
                for (int i = 0; i < currentMenus.Rows.Count; i++)
                {
                    string dataid = currentMenus.Rows[i]["MIID"].ToString();
                    string id     = currentMenus.Rows[i]["Layout"].ToString();
                    string pid    = id.Length <= 2 ? "00" : id.Substring(0, id.Length - 2);//上级id,如果当前layout是一级菜单,则为00,否则就是去掉后两位.(向前一级)
                    string name   = currentMenus.Rows[i]["MIName"].ToString();
                    string link   = currentMenus.Rows[i]["MiUrl"].ToString();
                    znodes += "{\"id\":\"" + id + "\",\"pId\":\"" + pid + "\",\"name\":\"" + name + "\",\"open\":\"true\",\"Link\":\"" + link + "\",\"DataId\":\"" + dataid + "\" },";
                }
                znodes = znodes.TrimEnd(',');
            }
            return(znodes);
        }
Esempio n. 7
0
        private void BindData()
        {
            //绑定当前用户名
            litManagerName.Text = currentManager.UserName;
            DataTable MenuInfo = new DataTable();

            if (litManagerName.Text != "yihui")
            {
                MenuInfo = AdminMenuHelper.GetCurrentRoleMenuInfo(ManagerHelper.GetCurrentManager().RoleId);
            }
            else
            {
                MenuInfo = AdminMenuHelper.GetAllAdminMenus();
            }
            //动态绑定当前角色的导航菜单
            for (int i = 0; i < MenuInfo.Rows.Count; i++)
            {
                if (MenuInfo.Rows[i]["Layout"].ToString().Length == 2)//只有是一级菜单才能添加
                {
                    this.litMenuBanner.Text += string.Format("<a onclick=\"ShowMenuLeft('{0}','{1}',null)\">{2}</a>", MenuInfo.Rows[i]["Layout"], MenuInfo.Rows[i]["MIurl"], MenuInfo.Rows[i]["MIName"]);
                }
            }
        }
Esempio n. 8
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //用MVC系统自带的功能 获取当前方法上的特性名称
            bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(NoNeedAdminAuthory), inherit: true) ||
                                     filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(NoNeedAdminAuthory), inherit: true);

            if (skipAuthorization)
            {
                return;
            }
            //检查是否登录
            if (!WebCookieHelper.AdminCheckLogin())
            {
                filterContext.Result = new RedirectResult("~/Admin/Account/Login", true);
                return;
            }
            //如果是超级管理就免去验证
            if (WebCookieHelper.GetAdminId(5) == 1)
            {
                return;
            }
            //页面权限验证开始
            var customAttributes = filterContext.ActionDescriptor.GetCustomAttributes(true);

            if (customAttributes != null && customAttributes.Length > 0)
            {
                for (int i = 0; i < customAttributes.Count(); i++)
                {
                    if (customAttributes.GetValue(i).GetType().Name == "AdminActionMethod")                    //判断anction特性名称
                    {
                        string actionCode       = (customAttributes[i] as AdminActionMethod).RoleCode;         //获取特性功能按钮代码
                        string actionUrl        = (customAttributes[i] as AdminActionMethod).ActionUrl;        //获取特性功能地址
                        int    actionResultType = (customAttributes[i] as AdminActionMethod).ActionResultType; //获取返回视图类型
                        if (actionCode == "NoNeedAuthory")                                                     //不需要权限认证
                        {
                            return;
                        }
                        else   //判断权限是否符合
                        {
                            List <AuthorDesign.Model.AdminPageAction> pageActionList = AdminMenuHelper.GetNowAdminMenu();
                            var pageSelect = pageActionList.Where(m => m.PageUrl == actionUrl);
                            if (pageSelect != null && pageSelect.Count() > 0)   //判断有无执行该页面的权利
                            //判断有误执行该动作权利
                            {
                                var codeList = AdminMenuHelper.LoadActionCodeList();
                                //先根据动作按钮代码查找到代码所在按钮Id
                                var codeSelect = codeList.Where(m => m.ActionCode == actionCode);
                                if (codeSelect != null && codeSelect.Count() > 0)
                                {
                                    int codeId = codeSelect.First().Id;
                                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                                    //判断codeId在角色动作列表中是否为选择状态
                                    string roleActionList = pageSelect.First().RoleActionList;

                                    List <AuthorDesign.Web.Areas.Admin.Models.RolePageActionModel> roleActionListModel = serializer.Deserialize <List <AuthorDesign.Web.Areas.Admin.Models.RolePageActionModel> >(roleActionList);
                                    if (roleActionListModel != null && roleActionListModel.Where(m => m.ActionId == codeId && m.actionChecked == 1).Count() > 0)
                                    {
                                        //判断CodeId在管理员动作列表中是否为选择状态
                                        List <AuthorDesign.Web.Areas.Admin.Models.RolePageActionModel> adminActionListModel = serializer.Deserialize <List <AuthorDesign.Web.Areas.Admin.Models.RolePageActionModel> >(pageSelect.First().AdminActionList);
                                        if (adminActionListModel != null && adminActionListModel.Where(m => m.ActionId == codeId && m.actionChecked == 1).Count() > 0)
                                        {
                                            StringBuilder sb = new StringBuilder();
                                            sb.Append("[");
                                            //传递在该页面可执行的按钮
                                            foreach (var item in roleActionListModel)
                                            {
                                                if (item.actionChecked == 1)
                                                {
                                                    var needChangeAction = adminActionListModel.Where(m => m.ActionId == item.ActionId).FirstOrDefault();
                                                    if (needChangeAction == null)
                                                    {
                                                        item.actionChecked = 0;
                                                    }
                                                    else if (needChangeAction.actionChecked == 0)
                                                    {
                                                        item.actionChecked = 0;
                                                    }
                                                }
                                                AuthorDesign.Model.PageAction OneAction = codeList.Where(m => m.Id == item.ActionId).FirstOrDefault();
                                                sb.Append("{").Append("\"").Append("ActionName").Append("\"").Append(":").Append("\"").Append(OneAction == null ? "" : OneAction.ActionCode).Append("\"").Append(",").Append("\"").Append("IsChecked").Append("\"").Append(":").Append(item.actionChecked).Append("}").Append(",");
                                            }
                                            sb.Remove(sb.Length - 1, 1);
                                            sb.Append("]");
                                            filterContext.Controller.ViewBag.CanOperationActionList = sb.ToString();
                                        }
                                        else
                                        {
                                            if (actionResultType == 0)
                                            {
                                                filterContext.Result = new RedirectResult("~/Admin/Home/NoAuthory", true);
                                            }
                                            else if (actionResultType == 1)
                                            {
                                                filterContext.Result = new JsonResult()
                                                {
                                                    Data = new { state = "error", message = "您暂无权限操作" }
                                                };
                                            }
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        if (actionResultType == 0)
                                        {
                                            filterContext.Result = new RedirectResult("~/Admin/Home/NoAuthory", true);
                                        }
                                        else if (actionResultType == 1)
                                        {
                                            filterContext.Result = new JsonResult()
                                            {
                                                Data = new { state = "error", message = "您暂无权限操作" }
                                            };
                                        }
                                        return;
                                    }
                                }
                                else
                                {
                                    if (actionResultType == 0)
                                    {
                                        filterContext.Result = new RedirectResult("~/Admin/Home/NoAuthory", true);
                                    }
                                    else if (actionResultType == 1)
                                    {
                                        filterContext.Result = new JsonResult()
                                        {
                                            Data = new { state = "error", message = "您暂无权限操作" }
                                        };
                                    }
                                    return;
                                }
                            }
                            else
                            {
                                if (actionResultType == 0)
                                {
                                    filterContext.Result = new RedirectResult("~/Admin/Home/NoAuthory", true);
                                }
                                else if (actionResultType == 1)
                                {
                                    filterContext.Result = new JsonResult()
                                    {
                                        Data = new { state = "error", message = "您暂无权限操作" }
                                    };
                                }
                                return;
                            }
                        }
                    }
                }
            }

            base.OnActionExecuting(filterContext);
        }