/// <summary>url解析成对象 /// </summary> /// <param name="url"></param> /// <param name="isPlugin">是否为插件</param> /// <returns></returns> public static UrlPathEntity getUrlPathEntity(string url, bool isPlugin) { UrlPathEntity result = null; var matchs = url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (isPlugin) { //var matchs = PluginRgx.Matches(url); if (matchs != null && matchs.Length > 0) { int _index = 0; result = new UrlPathEntity(); result.pluginname = matchs[_index++]; //插件名称 string _pluginversion = matchs[_index++]; //插件版本 int pluginversion = -1; int.TryParse(_pluginversion, out pluginversion); result.pluginversion = pluginversion; string urltemp = "/" + result.pluginname; for (; _index < matchs.Length - 1;) { urltemp += "/" + matchs[_index++]; } result.action = matchs[_index];//action名称 urltemp += "/" + result.action; CAModel controller = null;//控制器名称(包含area) UrlRefAction.TryGetValue(urltemp.ToLower(), out controller); if (controller != null) { result.controller = controller.ControllerName.Replace("/", "."); result.action = controller.ActionName; } } } else { if (matchs != null && matchs.Length > 0) { int _index = 0; result = new UrlPathEntity(); result.controller = string.Empty;//控制器名称(包含area) for (; _index < matchs.Length - 1;) { result.controller += "." + matchs[_index++]; } result.controller = result.controller.Substring(1); result.action = matchs[_index];//action名称 } } 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); }