/// <summary>获取权限树 /// </summary> /// <returns></returns> public string GetRightTree() { //List<RightEntity> list = new List<RightEntity>(); //for (int i = 0; i < 3; i++) //{ // RightEntity ri = new RightEntity(); // list.Add(ri); // ri.Id = i; // ri.IsMenu = 1; // ri.Level = 1; // ri.Name = "test" + i; // ri.ParentId = 0; // for (int j = 0; j < 3; j++) // { // RightEntity ro = new RightEntity(); // ri.Children.Add(ro); // ro.Id = i*10+j; // ro.IsMenu = 1; // ro.Level = 2; // ro.Name = "test" + i+"-"+j; // ro.ParentId = i; // } //} //return Newtonsoft.Json.JsonConvert.SerializeObject(list); var result = new RightBll().GetAllRights(); return JsonConvert.SerializeObject(result); }
// 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(); }
public ActionResult GetModule() { PluginBll _PluginBll = new PluginBll(); List<PluginEntity> pluginEntities = _PluginBll.GetPlugins(0,0,"").ToList(); RightBll rightBll = new RightBll(); List<int> list = rightBll.GetCategory(); if (list != null) pluginEntities.RemoveAll(m => list.Contains(m.Id)); StringBuilder sb = new StringBuilder(); foreach (var item in pluginEntities) { sb.AppendFormat("<option value = '{0}'>", item.Id); sb.Append(item.Name); sb.Append("</option>"); } return Content(sb.ToString()); }
/// <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); }
public ActionResult GetRights() { RightBll rightBll = new RightBll(); return Content(JsonConvert.SerializeObject( rightBll.GetAllRights())); }
/// <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; }
/// <summary>删除模块 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult DelModule(int id) { var entity = _PluginBll.GetPlugin(id); if (entity.Status == 1) { _PluginBll.DisablePlugin(id); } int result = _PluginBll.DelPlugin(id); if (entity.MenuShow == 1) { RightBll rightBll = new RightBll(); List<RightEntity> rightEntities = rightBll.GetRights(id); rightBll.DeleteRightRel(rightEntities.Select(m => m.Id).ToList()); } return Json(result); }