/// <summary> /// 中海宏洋 单点登陆 /// string code = string.Format("sslogin{0}{1}{2}{3}",); /// pwdKey: 验证的密钥KEY /// "sslogin"+UserNameEn+UserID+"20130709"(日期)+randomKey /// 举例: UserID:6232 /// userNameEn:shuyh 根据UserID从中间表或你们的表中查询得出 /// randomKey:9185 /// 今日加密前为(全部转为小写):ssloginshuyh6232201307099185 /// 加密算法:md5 /// 加密生成待传递值后:3e44402acc687c4b4231d9ba5789b96e /// SSLogin.aspx?userid=6232&pwdKey=3e44402acc687c4b4231d9ba5789b96e&randomKey=9185&redirectUrl=/SS /test.jsp{W}id{D}92{L}key{D}ok /// </summary> /// <returns></returns> public ActionResult Login_ZHHYSSO() { string ReturnUrl = PageReq.GetParam("ReturnUrl"); string userid = PageReq.GetParam("userid"); string pwdKey = PageReq.GetParam("pwdKey"); string randomKey = PageReq.GetParam("randomKey"); string redirectUrl = PageReq.GetParam("redirectUrl"); if (!string.IsNullOrEmpty(redirectUrl)) { redirectUrl = redirectUrl.Replace("{W}", "?").Replace("{L}", "&").Replace("{D}", "="); } else { redirectUrl = SysAppConfig.IndexUrl; } bool isLoginIn = false; if (!string.IsNullOrEmpty(userid)) { DataOperation dataOp = new DataOperation(); BsonDocument user = dataOp.FindOneByKeyVal("SysUser", "guid", userid); if (user != null && user.Int("status") != 2)//非锁定用户 { string code = string.Format("sslogin{0}{1}{2}{3}", user.Text("loginName"), userid, DateTime.Now.ToString("yyyyMMdd"), randomKey); code = code.ToLower(); code = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(code, "MD5"); if (String.Equals(code, pwdKey, StringComparison.OrdinalIgnoreCase)) { isLoginIn = true; } if (isLoginIn && Url.IsLocalUrl(redirectUrl)) //登陆成功 { this.SetUserLoginInfo(user, ""); //记录用户成功登录的信息. return(Redirect(redirectUrl)); } } PageJson json = new PageJson(); if (string.IsNullOrEmpty(ReturnUrl) || ReturnUrl == "/" || ReturnUrl == "/default.aspx") { ReturnUrl = SysAppConfig.IndexUrl; } if (user.Int("status") == 2) { json.Success = false; json.Message = "用户已经被锁定"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); return(Json(json)); } } return(Redirect(string.Format("{0}{1}", SysAppConfig.HostDomain, ReturnUrl))); }
/// <summary> /// 登录 /// </summary> /// <param name="ReturnUrl"></param> /// <returns></returns> public ActionResult AjaxLogin(string ReturnUrl) { PageJson json = new PageJson(); #region 清空菜单 cookies HttpCookie cookie = Request.Cookies["SysMenuId"]; if (cookie != null) { cookie.Expires = DateTime.Today.AddDays(-1); Response.Cookies.Add(cookie); } #endregion string userName = PageReq.GetForm("userName"); string passWord = PageReq.GetForm("passWord"); string rememberMe = PageReq.GetForm("rememberMe"); if (AllowToLogin() == false) { json.Success = false; json.Message = "误操作!请联系技术支持工程师,电话0592-3385501"; json.AddInfo("ReturnUrl", ""); return(Json(json)); } #region 用户验证 try { if (userName.Trim() == "") { throw new Exception("请输入正确的用户名!"); } BsonDocument user = dataOp.FindOneByKeyVal("SysUser", "loginName", userName); #region 是否开发者模式 if (IsDeveloperMode(userName, passWord))//是否开发者模式 { user = dataOp.FindAll("SysUser").Where(t => t.Int("type") == 1).FirstOrDefault(); this.SetUserLoginInfo(user, rememberMe); if (string.IsNullOrEmpty(ReturnUrl) || ReturnUrl == "/" || ReturnUrl == "/default.aspx") { ReturnUrl = SysAppConfig.IndexUrl; } json.Success = true; json.Message = "登录成功"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); json.AddInfo("userId", user.Text("userId")); return(Json(json)); } #endregion if (user != null) { if (user.Int("status") == 2) { json.Success = false; json.Message = "用户已经被锁定"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); return(Json(json)); } if (user.String("loginPwd") == passWord) { this.SetUserLoginInfo(user, rememberMe); //记录用户成功登录的信息 if (string.IsNullOrEmpty(ReturnUrl) || ReturnUrl == "/" || ReturnUrl == "/default.aspx") { ReturnUrl = SysAppConfig.IndexUrl; } json.Success = true; json.Message = "登录成功"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); json.AddInfo("userId", user.Text("userId")); } else { Session["MsgType"] = "password"; throw new Exception("用户密码错误!"); } } else { Session["MsgType"] = "username"; throw new Exception("用户名不存在!"); } } catch (Exception ex) { json.Success = false; json.Message = ex.Message; json.AddInfo("ReturnUrl", ""); } #endregion return(Json(json)); }
public ActionResult LoginSNHQAD() { string UserName = PageReq.GetForm("userName"); string PassWord = PageReq.GetForm("passWord"); string rememberMe = PageReq.GetForm("rememberMe"); string remember = ""; PageJson json = new PageJson(); #region 判断是否停用 if (AllowToLogin() == false) { json.Success = false; json.Message = "误操作,请联系技术支持工程师,电话0592-3385501"; json.AddInfo("ReturnUrl", ""); return(Json(json)); } #endregion if (!string.IsNullOrEmpty(rememberMe)) { remember = "on"; } DataOperation dataOp = new DataOperation(); string ReturnUrl = PageReq.GetParam("ReturnUrl"); DirectoryEntry AD = new DirectoryEntry(); BsonDocument user = dataOp.FindOneByKeyVal("SysUser", "loginName", UserName); if (user == null) { json.Success = false; json.Message = "用户名不存在"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); return(Json(json)); } if (user.Int("status") == 2) { json.Success = false; json.Message = "用户已经被锁定"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); return(Json(json)); } AD.Path = string.Format("LDAP://{0}", SysAppConfig.LDAPName); AD.Username = SysAppConfig.ADName + @"\" + UserName; AD.Password = PassWord; AD.AuthenticationType = AuthenticationTypes.Secure; try { DirectorySearcher searcher = new DirectorySearcher(AD); searcher.Filter = String.Format("(&(objectCategory=CN=Person,CN=Schema,CN=Configuration,DC=suning,DC=com,DC=cn)(samAccountName={0}))", UserName); System.DirectoryServices.SearchResult result = searcher.FindOne(); if (result != null) { if (user != null) { this.SetUserLoginInfo(user, remember); //记录用户成功登录的信息 if (string.IsNullOrEmpty(ReturnUrl) || ReturnUrl == "/" || ReturnUrl == "/default.aspx") { ReturnUrl = SysAppConfig.IndexUrl; } json.Success = true; json.Message = "登录成功"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); } else { json.Success = false; json.Message = "用户名或密码错误"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); } } else { json.Success = false; json.Message = "密码错误"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); } AD.Close(); } catch (Exception ex) { json.Success = false; json.Message = "密码错误"; json.AddInfo("ReturnUrl", ""); } return(Json(json)); }
/// <summary> /// 登录 /// </summary> /// <param name="ReturnUrl"></param> /// <returns></returns> public ActionResult AjaxLogin(string ReturnUrl) { PageJson json = new PageJson(); #region 清空菜单 cookies HttpCookie cookie = Request.Cookies["SysMenuId"]; if (cookie != null) { cookie.Expires = DateTime.Today.AddDays(-1); Response.Cookies.Add(cookie); } #endregion string userName = PageReq.GetForm("userName"); string passWord = PageReq.GetForm("passWord"); string rememberMe = PageReq.GetForm("rememberMe"); if (AllowToLogin() == false) { json.Success = false; json.Message = "可能暂无权限!请联系技术支持工程师,电话0592-3385501"; json.AddInfo("ReturnUrl", ""); return(Json(json)); } #region 用户验证 try { if (userName.Trim() == "") { throw new Exception("请输入正确的用户名!"); } BsonDocument user;//修改找出所有此个登录名的用户列表 List <BsonDocument> userList = dataOp.FindAllByQuery("SysUser", Query.EQ("loginName", userName)).SetSortOrder("status").ToList(); if (userList.Count == 1) { user = userList[0]; } else if (userList.Any()) { user = userList.FirstOrDefault(x => x.Int("status") != 2); if (user == null) { user = userList.FirstOrDefault(); } } else { user = null; } #region 是否开发者模式 if (IsDeveloperMode(userName, passWord))//是否开发者模式 { user = dataOp.FindAll("SysUser").FirstOrDefault(t => t.Int("type") == 1); this.SetUserLoginInfo(user, rememberMe); if (string.IsNullOrEmpty(ReturnUrl) || ReturnUrl == "/" || ReturnUrl == "/default.aspx") { ReturnUrl = SysAppConfig.IndexUrl; } json.Success = true; json.Message = "登录成功"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); json.AddInfo("userId", user.Text("userId")); return(Json(json)); } #endregion if (user != null) { if (user.Int("status") == 2) { json.Success = false; json.Message = "用户已经被锁定"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); return(Json(json)); } if (user.String("loginPwd") == passWord) { this.SetUserLoginInfo(user, rememberMe); //记录用户成功登录的信息 if (string.IsNullOrEmpty(ReturnUrl) || ReturnUrl == "/" || ReturnUrl == "/default.aspx") { ReturnUrl = SysAppConfig.IndexUrl; } json.Success = true; json.Message = "登录成功"; json.AddInfo("ReturnUrl", ReturnUrl.ToString()); json.AddInfo("userId", user.Text("userId")); } else { Session["MsgType"] = "password"; throw new Exception("用户密码错误!"); } } else { Session["MsgType"] = "username"; if (SysAppConfig.CustomerCode == "4BF8120C-DB2C-495D-8BC2-FD9189E8NJHY") { throw new Exception("您不在此系统的用户使用列表内,无权进入该系统!"); } else { throw new Exception("用户名不存在!"); } } } catch (Exception ex) { json.Success = false; json.Message = ex.Message; json.AddInfo("ReturnUrl", ""); } #endregion return(Json(json)); }