Пример #1
0
        /// <summary>
        /// 通过角色ID获取角色信息
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        private async Task <ResponseBase> GetRoleView(long roleId)
        {
            var role = await _sysUserRoleBll.GetSysUserRole(roleId);

            if (role == null)
            {
                return(new ResponseBase().GetResponseError(StatusCode.UserRole30001, "角色不存在"));
            }
            var authorityCore = new AuthorityCore(role.AuthorityValue.ToBigInteger());
            var menu          = MenuLib.MenuConfigs.Select(p => new MenuView()
            {
                Id       = p.Id,
                Name     = p.Name,
                PerCode  = p.PerCode,
                Type     = p.Type,
                IsOwner  = authorityCore.Validation(p.Id),
                FatherId = p.FatherId
            }).ToList();
            var roleView = new GetUserRoleView()
            {
                Name    = role.Name,
                Menus   = ConvertToRoleMenu(menu),
                MyMenus = menu.Where(p => p.IsOwner).Select(p => p.Id).ToList()
            };

            return(ResponseBase.Success(roleView));
        }
Пример #2
0
        /// <summary>
        /// 通过选择的菜单ID,计算权值
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        private string GetAuthorityValue(int[] ids)
        {
            var authorityCore = new AuthorityCore();
            var weightSum     = authorityCore.AuthoritySum(ids);

            return(weightSum.ToString());
        }
Пример #3
0
 /// <summary>
 /// 添加父权限
 /// </summary>
 /// <param name="authorityCore"></param>
 private void InitFatherMenu(AuthorityCore authorityCore)
 {
     foreach (var menu in MenuLib.MenuConfigs)
     {
         if (authorityCore.Validation(menu.Id))
         {
             AddFatherMenu(authorityCore, menu.FatherId);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// 移除所有子权限
        /// </summary>
        /// <param name="authorityCore"></param>
        /// <param name="fatherId"></param>
        private void RemoveChildrenMenu(AuthorityCore authorityCore, int fatherId)
        {
            var menus = MenuLib.MenuConfigs.Where(p => p.FatherId == fatherId).ToList();

            foreach (var menu in menus)
            {
                authorityCore.WeakenAuthority(menu.Id);
                RemoveChildrenMenu(authorityCore, menu.Id);
            }
        }
Пример #5
0
        /// <summary>
        /// 处理“查看”动作权限
        /// 必须拥有页面“查看”动作权限,该页面其它子权限才会生效
        /// </summary>
        /// <param name="authorityCore"></param>
        private void HandleShowAction(AuthorityCore authorityCore)
        {
            var showActionMenus = MenuLib.MenuConfigs.Where(p => p.Type == (int)MenuEnum.ShowAction).ToList();

            foreach (var showActionMenu in showActionMenus)
            {
                if (!authorityCore.Validation(showActionMenu.Id))
                {
                    RemoveChildrenMenu(authorityCore, showActionMenu.FatherId);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 增加父ID
        /// </summary>
        /// <param name="authorityCore"></param>
        /// <param name="fatherId"></param>
        private void AddFatherMenu(AuthorityCore authorityCore, int fatherId)
        {
            if (fatherId == 0)
            {
                return;
            }
            var father = MenuLib.MenuConfigs.FirstOrDefault(p => p.Id == fatherId);

            if (father != null)
            {
                authorityCore.RegisterAuthority(fatherId);
                AddFatherMenu(authorityCore, father.FatherId);
            }
        }
Пример #7
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            #region 加载Tree

            AuthorityCore licenses = new AuthorityCore();

            //菜单
            menuJson = licenses.GetMenu();


            // 角色
            roleJson = licenses.GetRole();

            //模块
            //  moudleJson = licenses.GetModules();
            #endregion
        }
Пример #8
0
        /// <summary>
        /// 执行方法之前,验证用户角色权限
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;

            if (actionDescriptor != null)
            {
                var authorityConfig = MenuLib.MenuConfigs.FirstOrDefault(p => p.Controller == actionDescriptor.ControllerName && p.Action == actionDescriptor.ActionName);
                if (authorityConfig != null)
                {
                    var isCanVisit = new AuthorityCore(AppTicket.GetAppTicket(context.HttpContext).WeightSum).Validation(authorityConfig.Id);
                    if (!isCanVisit)
                    {
                        context.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden;
                        context.Result = new JsonResult(new ResponseBase().GetResponseForbidden());
                    }
                }
            }
        }
Пример #9
0
        /// <summary>
        /// 获取登录者菜单
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public ResponseBase ProcessAction(HttpContext httpContext)
        {
            var ticket        = AppTicket.GetAppTicket(httpContext);
            var authorityCore = new AuthorityCore(ticket.WeightSum);

            HandleShowAction(authorityCore);
            InitFatherMenu(authorityCore);
            var menus = MenuLib.MenuConfigs.Where(p => authorityCore.Validation(p.Id)
                                                  )
                        .Select(p => new MenuView()
            {
                Id      = p.Id,
                IsOwner = true,
                Name    = p.Name,
                PerCode = p.PerCode,
                Type    = p.Type
            }).ToList();

            return(ResponseBase.Success(menus));
        }
Пример #10
0
 void Licenses(string roleNodeXml, string menuNodeXml, string modulXml, string type)
 {
     if (roleNodeXml != "")
     {
         AuthorityCore licenses = new AuthorityCore();
         if (type == "3")
         {
             if (menuNodeXml != "")
             {
                 licenses.DeleteMenuLicenses(roleNodeXml, menuNodeXml, type);
             }
             if (modulXml != "")
             {
                 licenses.DeleteModelLicenses(roleNodeXml, modulXml, type);
             }
         }
         else
         {
             licenses.Licenses(roleNodeXml, menuNodeXml, modulXml, type);
         }
     }
 }
Пример #11
0
        public void ProcessRequest(HttpContext context)
        {
            Opt = context.Request["opt"] == null ? "" : context.Request["opt"];
            try
            {
                switch (Opt)
                {
                case "Menu":
                    strMenuRoleXML = context.Request["MenuRoleXML"] == null ? "" : context.Request["MenuRoleXML"];
                    AuthorityCore licenses = new AuthorityCore();
                    context.Response.Clear();
                    context.Response.Write(licenses.GetUnionMenu(strMenuRoleXML) + "&");     //AuthorityOpt
                    context.Response.End();
                    break;

                case "License":
                    strLicenseRoleXml   = context.Request["RoleXML"] == null ? "" : context.Server.UrlDecode(context.Request["RoleXML"]);
                    strLicenseMenuXml   = context.Request["MenuXML"] == null ? "" :  context.Server.UrlDecode(context.Request["MenuXML"]);
                    strLicenseModuleXml = context.Request["ModuleXML"] == null ? "" : context.Request["ModuleXML"];
                    strLicenseType      = context.Request["Action"] == null ? "" : context.Request["Action"];
                    Licenses(strLicenseRoleXml, strLicenseMenuXml, strLicenseModuleXml, strLicenseType);
                    context.Response.Clear();
                    context.Response.Write(true);
                    context.Response.End();
                    break;
                }
            }
            catch (ThreadAbortException eb)
            {
            }
            catch
            {
                context.Response.Clear();
                context.Response.Write(false);
                context.Response.End();
            }
        }