Пример #1
0
        // GET: /Home/

        public ActionResult Index()
        {
            UserEntity user = new UserBll().getCurUser();
            ViewBag.User = user;
            #region 菜单呈现
            List<string> urights = new List<string>();
            List<MenuEntity> menus = new List<MenuEntity>();
            if (user != null)
            {

                IEnumerable<PluginEntity> pluginEntities = HuberPluginHandle.getEntityForMenu();
                if (pluginEntities.Any())
                {
                    #region 用户的权限
                    List<RoleEntity> uroles = new RoleBll().GetRoles(user.RolesIds);
                    string[] rightRange = null;
                    string[] splitchar = new string[] { "," };
                    if (uroles != null)
                        foreach (RoleEntity role in uroles)
                        {
                            rightRange = role.RightIds.Split(splitchar, StringSplitOptions.RemoveEmptyEntries);
                            if (rightRange != null)
                            {
                                urights.AddRange(rightRange);
                            }
                        }
                    #endregion
                    List<RightEntity> rightEntities = new RightBll().GetAllMenu(urights, user.Uid == UserBll.SuperAdminID);
                    foreach (PluginEntity pluginEntity in pluginEntities)
                    {
                        RightEntity rightEntity = rightEntities.SingleOrDefault(m => m.Category == pluginEntity.Id && m.ParentId == 0);
                        if (rightEntity == null)
                            continue;
                        MenuEntity menuEntity = GetMenu(rightEntity, pluginEntity);
                        menus.Add(menuEntity);
                    }
                }
                #region 添加系统菜单
                if (user.Uid == UserBll.SuperAdminID)
                {
                    MenuEntity CoreMenu = new MenuEntity(-1, "系统管理", string.Empty, true, "fa fa-cog");
                    CoreMenu.Children.Add(new MenuEntity(-1, "用户管理", "/user/index", true));
                    CoreMenu.Children.Add(new MenuEntity(-1, "权限管理", "/right/index", true));
                    CoreMenu.Children.Add(new MenuEntity(-1, "角色管理", "/role/index", true));
                    CoreMenu.Children.Add(new MenuEntity(-1, "模块管理", "/module/index", true));
                    menus.Add(CoreMenu);
                    //menus.Add(CoreMenu);
                    //menus.Add(CoreMenu);
                    //menus.Add(CoreMenu);
                    //menus.Add(CoreMenu);
                }
                #endregion
            }
            #endregion



            ViewBag.Menus = menus;
            return View();
        }
Пример #2
0
 /// <summary>添加角色 
 /// </summary>
 /// <param name="name">角色名称</param>
 /// <param name="isSuper">是否为管理员</param>
 /// <returns></returns>
 public ActionResult AddRole(string name, int isSuper)
 {
     RoleBll roleBll = new RoleBll();
     bool result = roleBll.AddRole(new RoleEntity()
      {
          Name = name,
          IsSuper = isSuper
      });
     return Json(result);
 }
Пример #3
0
 /// <summary>角色列表 
 /// </summary>
 /// <param name="pageIndex">页码</param>
 /// <param name="pageSize">页容量</param>
 /// <param name="callBack"></param>
 /// <returns></returns>
 public ActionResult RoleList(int pageIndex, int pageSize, string callBack, string RoleName)
 {
     int count = 0;
     RoleBll roleBll = new RoleBll();
     List<RoleEntity> roleEntities = roleBll.GetRoles(pageIndex, pageSize, RoleName, out count);
     ViewBag.PageIndex = pageIndex;
     ViewBag.PageCount = count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1;
     ViewBag.callback = callBack;
     return PartialView(roleEntities);
 }
Пример #4
0
        /// <summary>验证登录
        /// </summary>
        /// <returns>2 具有访问权限 1 没有权限  0 未登录</returns>
        public int chekLogin(ref string uid, bool liwai, List <RightEntity> userRights)
        {
            int    result = 0;
            string sign   = CookieFunc.ReadCookie(CoSignKey);

            if (sign != null && sign != string.Empty)
            {
                uid = string.Empty;
                string   pwd = string.Empty;
                DateTime dt  = DateTime.Now;
                if (design(sign, ref uid, ref pwd, ref dt))
                {
                    if (dt.AddDays(15) > DateTime.Now)//令牌未过期
                    {
                        int signState = new LoginDal().exsitLoginSign(uid, sign, IsOnlyOne);
                        if (signState == 1)
                        {
                            result = 1;
                        }
                        else if (signState == -1)
                        {
                            if (1 == new UserDal().login(uid, pwd))
                            {
                                result = 1;
                            }
                        }
                        if (result > 0)
                        {
                            if (!liwai)
                            {
                                #region 获取当前页面的权限
                                UrlPathEntity      urlEntity = null;
                                List <RightEntity> rlist     = null;
                                if (HttpContext.Current.Request.RawUrl.StartsWith("/Plugins/"))
                                {
                                    urlEntity = HuberPluginHandle.getUrlPathEntity(HttpContext.Current.Request.RawUrl.Substring(8), true);
                                    rlist     = new RightBll().UserGetRights("/" + urlEntity.pluginname + "/" + urlEntity.controller + "/" + urlEntity.action);
                                }
                                else
                                {
                                    urlEntity = HuberPluginHandle.getUrlPathEntity(HttpContext.Current.Request.RawUrl, false);
                                    rlist     = new RightBll().UserGetRights("/" + urlEntity.controller + "/" + urlEntity.action);
                                }
                                UserEntity CurUer = new UserDal().GetUser(uid);
                                if (CurUer != null)
                                {
                                    if (rlist.Count > 0)
                                    {
                                        List <RightEntity> urights      = new List <RightEntity>();
                                        string             rightCompara = ",{0},";

                                        if (CurUer.Uid == SuperAdminID)//如果是超级管理员,不需要对权限筛选
                                        {
                                            urights = rlist;
                                        }
                                        else
                                        {
                                            List <RoleEntity> uRoles = new RoleBll().GetRoles(CurUer.RolesIds);
                                            if (uRoles != null && uRoles.Count > 0)
                                            {
                                                foreach (RightEntity right in rlist)
                                                {
                                                    foreach (RoleEntity role in uRoles)
                                                    {
                                                        if (role.RightIds.IndexOf(string.Format(rightCompara, right.Id)) > -1)
                                                        {
                                                            urights.Add(right);
                                                        }
                                                    }
                                                }
                                            }
                                        }


                                        userRights = urights;
                                        result     = 2;
                                    }
                                    else
                                    {
                                        if (CurUer.Uid == SuperAdminID)//如果是超级管理员,不需要对权限筛选
                                        {
                                            result = 2;
                                        }
                                    }
                                }



                                #endregion
                            }
                            else
                            {
                                result = 2;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #5
0
 public ActionResult UpdateRight(int rightId, string rights)
 {
     RoleBll roleBll = new RoleBll();
     bool result = roleBll.UpdateRight(rightId, rights);
     return Json(result);
 }
Пример #6
0
 /// <summary>修改角色 
 /// </summary>
 /// <param name="roleEntity"></param>
 /// <returns></returns>
 public ActionResult UpdateRole(RoleEntity roleEntity)
 {
     RoleBll roleBll = new RoleBll();
     bool result = roleBll.UpdateRole(roleEntity);
     return Json(result);
 }
Пример #7
0
 /// <summary>删除角色 
 /// </summary>
 /// <param name="roleId">角色Id</param>
 /// <returns></returns>
 public ActionResult DeleteRole(int roleId)
 {
     RoleBll roleBll = new RoleBll();
     bool result = roleBll.DeleteRole(roleId);
     return Json(result);
 }
Пример #8
0
        /// <summary>验证登录
        /// </summary>
        /// <returns>2 具有访问权限 1 没有权限  0 未登录</returns>
        public int chekLogin(ref string uid, bool liwai, List<RightEntity> userRights)
        {
            int result = 0;
            string sign = CookieFunc.ReadCookie(CoSignKey);
            if (sign != null && sign != string.Empty)
            {
                uid = string.Empty;
                string pwd = string.Empty;
                DateTime dt = DateTime.Now;
                if (design(sign, ref uid, ref pwd, ref dt))
                {
                    if (dt.AddDays(15) > DateTime.Now)//令牌未过期
                    {
                        int signState = new LoginDal().exsitLoginSign(uid, sign, IsOnlyOne);
                        if (signState == 1)
                        {
                            result = 1;
                        }
                        else if (signState == -1)
                        {
                            if (1 == new UserDal().login(uid, pwd))
                            {
                                result = 1;
                            }
                        }
                        if (result > 0)
                        {
                            if (!liwai)
                            {
                                #region 获取当前页面的权限
                                UrlPathEntity urlEntity = null;
                                List<RightEntity> rlist = null;
                                if (HttpContext.Current.Request.RawUrl.StartsWith("/Plugins/"))
                                {

                                    urlEntity = HuberPluginHandle.getUrlPathEntity(HttpContext.Current.Request.RawUrl.Substring(8), true);
                                    rlist = new RightBll().UserGetRights("/" + urlEntity.pluginname + "/" + urlEntity.controller + "/" + urlEntity.action);
                                }
                                else
                                {
                                    urlEntity = HuberPluginHandle.getUrlPathEntity(HttpContext.Current.Request.RawUrl, false);
                                    rlist = new RightBll().UserGetRights("/" + urlEntity.controller + "/" + urlEntity.action);
                                }
                                UserEntity CurUer = new UserDal().GetUser(uid);
                                if (CurUer != null)
                                {
                                    if (rlist.Count > 0)
                                    {
                                        List<RightEntity> urights = new List<RightEntity>();
                                        string rightCompara = ",{0},";

                                        if (CurUer.Uid == SuperAdminID)//如果是超级管理员,不需要对权限筛选
                                        {
                                            urights = rlist;
                                        }
                                        else
                                        {
                                            List<RoleEntity> uRoles = new RoleBll().GetRoles(CurUer.RolesIds);
                                            if (uRoles != null && uRoles.Count > 0)
                                            {
                                                foreach (RightEntity right in rlist)
                                                {
                                                    foreach (RoleEntity role in uRoles)
                                                    {
                                                        if (role.RightIds.IndexOf(string.Format(rightCompara, right.Id)) > -1)
                                                        {
                                                            urights.Add(right);
                                                        }
                                                    }
                                                }
                                            }
                                        }


                                        userRights = urights;
                                        result = 2;
                                    }
                                    else
                                    {
                                        if (CurUer.Uid == SuperAdminID)//如果是超级管理员,不需要对权限筛选
                                        {
                                            result = 2;
                                        }
                                    }
                                }



                                #endregion
                            }
                            else
                            {
                                result = 2;
                            }

                        }
                    }
                }
            }
            return result;
        }
Пример #9
0
 public ActionResult GetRoles2()
 {
     RoleBll roleBll = new RoleBll();
     List<RoleEntity> roleEntities = roleBll.GetRoles();
     var data = roleEntities.Select(m => new { m.Id, m.Name });
     return Json(data, JsonRequestBehavior.AllowGet);
 }
Пример #10
0
 public ActionResult GetRoles(int pageIndex, int pageSize)
 {
     RoleBll roleBll = new RoleBll();
     int count = 0;
     List<RoleEntity> roleEntities = roleBll.GetRoles(pageIndex, pageSize,"", out count);
     return PartialView(roleEntities);
 }
Пример #11
0
 public ActionResult GetUserRoles(string uId, string roldIds)
 {
     RoleBll roleBll = new RoleBll();
     List<RoleEntity> roleEntities = roleBll.GetRoles(roldIds);
     ViewData["uId"] = uId;
     return PartialView(roleEntities);
 }