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); FormsAuthentication.SignOut(); SessionHelper.DelAll(); throw ex; } }