public ActionResult Index() { if (true) { var user = _user.GetUserInfo("admin", StringHelper.GetMd5("123123"));//StringHelper.GetMd5(userPassWord) //更新用户登录信息 string userIP = WebCommon.GetIPAddress(); int result = _user.UpdateUserLoginInfo(user.Id, userIP); //唯一标识ID string userGuid = WebCommon.GetOnlyCode(); //拼接cookies字符串 var userData = user.Id + "|" + user.UserName + "|" + user.UserNickName + "|" + user.UserType + "|" + user.RegistIP + "|" + userIP + "|" + userGuid; //用户信息写入cookies FormsAuthentication.SetAuthCookie(userData, false); var cookie = new HttpCookie("remember"); cookie.Value = userData; Response.Cookies.Add(cookie); string resultStr = OperatorHelper.Instance.AddLoginUser(user.UserName, Entity.Enum.ReadonlyKey.LoginAppId);//写入缓存信息 return(RedirectToAction("index", "Home")); } return(View()); }
public bool UserLogin(string userName, string userPassWord, string checkCode, out string msg) { if (string.IsNullOrEmpty(userName.Trim())) { msg = "登录失败,用户名不能为空"; return(false); } if (string.IsNullOrEmpty(userPassWord.Trim())) { msg = "登录失败,用户密码不能为空"; return(false); } if (string.IsNullOrEmpty(checkCode.Trim())) { msg = "登录失败,验证码不能为空"; return(false); } try { string code = WebHelper.GetSession("session_verifycode"); if (code.ToLower() != checkCode.ToLower()) { msg = "登录失败,验证码错误"; return(false); } var user = _user.GetUserInfo(userName, userPassWord);//StringHelper.GetMd5(userPassWord) if (user == null) { msg = "登录失败,用户名或密码不正确"; return(false); } if (user.Valid == StructDictCode.状态.注销) { msg = "登录失败,该用户已经注销"; return(false); } //更新用户登录信息 string userIP = WebCommon.GetIPAddress(); int result = _user.UpdateUserLoginInfo(user.Id, userIP); //唯一标识ID string userGuid = WebCommon.GetOnlyCode(); //拼接cookies字符串 var userData = user.Id + "|" + user.UserName + "|" + user.UserNickName + "|" + user.UserType + "|" + user.RegistIP + "|" + userIP + "|" + userGuid; //用户信息写入cookies FormsAuthentication.SetAuthCookie(userData, false); var cookie = new HttpCookie("remember"); cookie.Value = userData; Response.Cookies.Add(cookie); string resultStr = OperatorHelper.Instance.AddLoginUser(user.UserName, Entity.Enum.ReadonlyKey.LoginAppId);//写入缓存信息 WebSecurityHelper.LogCommon.Current.WriteLog_Login(true, true); msg = "登录成功"; //删除验证码 WebHelper.RemoveSession("session_verifycode"); return(true); } catch (Exception ex) { msg = "登录失败,网络异常"; LogCommon.Current.WriteLog_Exception(msg + "===" + ex.Message); LogHelper.Error(ex); throw ex; } }
public JsonResult userlogin(string userName, string userPwd, string verificaCode, string verificaCode1) { string msg = ""; try { #region 验证用户 if (string.IsNullOrEmpty(userName.Trim())) { return(Fail("登录失败,用户名不能为空")); } else if (string.IsNullOrEmpty(userPwd.Trim())) { return(Fail("登录失败,用户密码不能为空")); } else if (string.IsNullOrEmpty(verificaCode.Trim())) { return(Fail("登录失败,验证码不能为空")); } else if (string.IsNullOrEmpty(verificaCode1.Trim())) { return(Fail("登录失败,验证码错误")); } string code = GetCache <string>("cacheCode"); if (Md5Helper.Encrypt(verificaCode.ToLower(), 16) != code || code != verificaCode1) { return(Fail("验证码错误,请刷新")); } //var user = _user.GetUserInfo(userName, StringHelper.GetMd5(userPwd)); T_User user = _user.GetUserByPhone(userName); if (user == null) { return(Fail("登录失败,用户名或密码不正确")); } else if (user.isProxy != 1) { return(Fail("非代理不允许登录")); } #endregion //唯一标识ID string userGuid = WebCommon.GetOnlyCode(); //拼接cookies字符串 //用户信息写入cookies FormsAuthentication.SetAuthCookie(userName, false); var cookie = new HttpCookie("remember"); cookie.Value = userName; Response.Cookies.Add(cookie); string resultStr = OperatorHelper.Instance.AddLoginUser(userName, Entity.Enum.ReadonlyKey.LoginAppId); //写入缓存信息 SessionHelper.Del("CheckCode"); //删除验证码 WebHelper.RemoveSession("session_verifycode"); SetCache <T_User>("session_user", user); var data = new { code = 1, body = new { access_token = userGuid }, msg = "登录成功" }; return(Success(data)); } catch (Exception ex) { msg = "API :: 登录失败,网络异常"; LogCommon.Current.WriteLog_Exception(msg + "===" + ex.Message); LogHelper.Error(ex); return(Fail(msg)); } }