/// <summary>获取当前用户的账号和姓名 /// </summary> /// <param name="uid"></param> /// <param name="uname"></param> /// <returns></returns> public UserEntity getCurUser() { UserEntity result = null; string sign = CookieFunc.ReadCookie(CoSignKey); if (sign != null && sign != string.Empty) { string uid = string.Empty; string pwd = string.Empty; DateTime dt = DateTime.Now; if (design(sign, ref uid, ref pwd, ref dt)) { result = new UserBll().GetUser(uid); } } return(result); }
/// <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); }