/// <summary> /// 登录 /// </summary> /// <returns></returns> public ActionResult Index() { HttpCookie cookie = Request.Cookies["USERINFO"]; if (cookie == null) { return(View()); } string USERNAME = cookie.Values["USERNAME"]; string PASSWORD = cookie.Values["PASSWORD"]; if (string.IsNullOrEmpty(USERNAME) || string.IsNullOrEmpty(PASSWORD)) { cookie.Expires = DateTime.Now.AddDays(-30); Response.AppendCookie(cookie); } else { var usersBll = new UsersBll(); var item = usersBll.LoginUsers(HashEncrypt.DecryptQueryString(USERNAME), HashEncrypt.DecryptQueryString(PASSWORD)); if (item != null) { Session["USERID"] = HashEncrypt.EncryptQueryString(item.UserID.ToString()); return(RedirectPermanent("../Home/Index")); } else { cookie.Expires = DateTime.Now.AddDays(-30); Response.AppendCookie(cookie); } } return(View()); }
public string setPassword(string bizContent, long timeStamp, string signature) { MessageLog.WriteLog(new LogParameterModel { ClassName = this.GetType().ToString(), MethodName = "setPassword", MethodParameters = $"bizContent:{bizContent},timeStamp:{timeStamp},signature:{signature}", LogLevel = ELogLevel.Info, Message = "接收参数", PathPrefix = "/log/ws", LogExt = "txt" }); var result = new ResultModel(); var paramItem = CommonLib.JsonHelper.Deserialize <ChangePasswordDto>(bizContent); if (paramItem == null) { result.resultCode = 0; result.resultMessage = "操作失败:bizContent不合法."; return(result.ToJSON()); } var cBll = new UsersBll(); var item = cBll.LoginUsers(paramItem.userId, paramItem.oldPassword); if (item != null) { var isFlag = cBll.ChangePassword(paramItem.welfareCentreId, paramItem.userId, paramItem.newPassword); if (isFlag) { result.resultCode = 1; result.resultMessage = "修改密码成功."; } else { result.resultCode = 0; result.resultMessage = "操作失败."; } } else { result.resultCode = 0; result.resultMessage = "旧密码错误."; } return(result.ToJSON()); }
/// <summary> /// 登录验证 /// </summary> /// <returns></returns> public JsonResult LoginSystem() { //System.Threading.Thread.Sleep(5000); int isCookieUp = 1; //1:cookie用户名和密码;2:cookie用户名;3:不要cookie bool isCode = true; //是否有验证码,默认有(true) string UserName = RequestParameters.Pstring("UserName"); string Password = RequestParameters.Pstring("Password"); bool Remember = RequestParameters.Pstring("Remember") == "1";//记住密码 string code = RequestParameters.Pstring("code"); if (UserName.Length <= 0) { var sReturnModel = new ResultMessage(); sReturnModel.ErrorType = 0; sReturnModel.MessageContent = "用户名不能为空."; return(Json(sReturnModel)); } if (Password.Length <= 0) { var sReturnModel = new ResultMessage(); sReturnModel.ErrorType = 0; sReturnModel.MessageContent = "密码不能为空."; return(Json(sReturnModel)); } if (code.Length <= 0) { var sReturnModel = new ResultMessage(); sReturnModel.ErrorType = 0; sReturnModel.MessageContent = "验证码不能为空."; return(Json(sReturnModel)); } if (!IsOkValidateCode(isCode, code)) { ClearValidateCode(isCode); var sReturnModel = new ResultMessage { ErrorType = 0, MessageContent = "验证码错误." }; return(Json(sReturnModel)); } ClearValidateCode(isCode); var usersBll = new UsersBll(); if (usersBll.ValidationUserName(UserName)) { var sReturnModel = new ResultMessage { ErrorType = 0, MessageContent = "用户名不存在." }; return(Json(sReturnModel)); } var item = usersBll.LoginUsers(UserName, HashEncrypt.BgPassWord(Password)); if (item != null) { #region 设置IP string GetIP = RequestParameters.Pstring("YlyClientIP"); //登录IP var itemUsers = new Users(); itemUsers.UserID = Utits.CurrentUserID; itemUsers.UserCode = GetIP; var cBllUsers = new UsersBll(); bool IsFlagUsers = cBllUsers.AddOrUpdate(itemUsers, false); #endregion try { Session["USERID"] = HashEncrypt.EncryptQueryString(item.UserID.ToString()); Session["WelfareCentreId"] = HashEncrypt.EncryptQueryString(item.WelfareCentreID.ToString()); if (Remember) { #region 记住内容详细 if (isCookieUp == 1) //记住用户名和密码 { #region Cookie HttpCookie cookies = Request.Cookies["USERINFO"]; if (cookies != null) { cookies.Expires = DateTime.Now.AddDays(-30); Response.AppendCookie(cookies); } HttpCookie cookie = new HttpCookie("USERINFO"); cookie.Values.Add("USERNAME", HashEncrypt.EncryptQueryString(UserName)); cookie.Values.Add("PASSWORD", HashEncrypt.EncryptQueryString(HashEncrypt.BgPassWord(Password))); cookie.Values.Add("WelfareCentreId", HashEncrypt.EncryptQueryString(item.WelfareCentreID.ToString())); cookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(cookie); #endregion } else if (isCookieUp == 2) //记住用户名不记住密码 { #region Cookie HttpCookie cookies = Request.Cookies["USERINFO"]; if (cookies != null) { cookies.Expires = DateTime.Now.AddDays(-30); Response.AppendCookie(cookies); } HttpCookie cookie = new HttpCookie("USERINFO"); cookie.Values.Add("USERNAME", HashEncrypt.EncryptQueryString(UserName)); cookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(cookie); #endregion } else //都不用记 { } #endregion } } catch (Exception ex) { Console.WriteLine(ex.Message); } var sReturnModel = new ResultMessage { ErrorType = 1, MessageContent = "登录成功." }; return(Json(sReturnModel)); } else { var sReturnModel = new ResultMessage { ErrorType = 0, MessageContent = "密码错误." }; return(Json(sReturnModel)); } }