/// <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)); } }
public JsonResult LoginSystem() { #region 后台系统登录 string UserName = RequestParameters.Pstring("UserName"); string Password = RequestParameters.Pstring("Password"); if (UserName.Length <= 0) { var sReturnModel = new ReturnMessageModel(); sReturnModel.ErrorType = 2; sReturnModel.MessageContent = "用户名不能为空."; return(Json(sReturnModel)); } if (Password.Length <= 0) { var sReturnModel = new ReturnMessageModel(); sReturnModel.ErrorType = 2; sReturnModel.MessageContent = "密码不能为空."; return(Json(sReturnModel)); } // string retVal = ""; #region try { var usersBll = new BLL_User(); var item = usersBll.GetObjectByUser(UserName, HashEncrypt.BgPassWord(Password)); if (item != null) { if (item.user_Sign == (int)StageMode.Normal) { Session["EQUI_USERID"] = HashEncrypt.EncryptQueryString(item.user_Id.ToString()); var sReturnModel = new ReturnMessageModel(); sReturnModel.ErrorType = 1; sReturnModel.MessageContent = "登录成功."; return(Json(sReturnModel)); } else { var sReturnModel = new ReturnMessageModel(); sReturnModel.ErrorType = 2; sReturnModel.MessageContent = "该账号已停用."; return(Json(sReturnModel)); } // retVal = "该账号已停用."; //登录成功 } else { var sReturnModel = new ReturnMessageModel(); sReturnModel.ErrorType = 2; sReturnModel.MessageContent = "账号或密码错误."; return(Json(sReturnModel)); } } catch (Exception ex) { var sReturnModel = new ReturnMessageModel(); sReturnModel.ErrorType = 2; sReturnModel.MessageContent = "系统异常:" + ex.Message; return(Json(sReturnModel)); // retVal = "1系统异常:" ; } #endregion //if (retVal == "1") //{ // var sReturnModel = new ReturnMessageModel(); // sReturnModel.ErrorType = 1; // sReturnModel.MessageContent = "登录成功."; // return Json(sReturnModel); //} //else //{ // var sReturnModel = new ReturnMessageModel(); // sReturnModel.ErrorType = 2; // sReturnModel.MessageContent = retVal; // return Json(sReturnModel); //} #endregion }
/// <summary> /// 修改密码 /// </summary> /// <returns></returns> public JsonResult ModifyPassword() { Guid iUSERID = Utits.CurrentUserID; if (iUSERID == Guid.Empty) { var sRetrunModel = new ResultMessage(); sRetrunModel.ErrorType = 3; sRetrunModel.MessageContent = "未登录."; return(Json(sRetrunModel)); } string szOldPassword = RequestParameters.Pstring("OldPassword"); if (szOldPassword.Length <= 0) { var sRetrunModel = new ResultMessage(); sRetrunModel.ErrorType = 0; sRetrunModel.MessageContent = "旧密码不能为空."; return(Json(sRetrunModel)); } string szNewPassword = RequestParameters.Pstring("NewPassword"); if (szNewPassword.Length <= 0) { var sRetrunModel = new ResultMessage(); sRetrunModel.ErrorType = 0; sRetrunModel.MessageContent = "新密码不能为空."; return(Json(sRetrunModel)); } var cBll = new UsersBll(); var item = cBll.GetObjectById(iUSERID); if (item == null) { var sRetrunModel = new ResultMessage(); sRetrunModel.ErrorType = 0; sRetrunModel.MessageContent = "用户名不存在."; return(Json(sRetrunModel)); } if (CommonLib.HashEncrypt.BgPassWord(szOldPassword) != item.Password) { var sRetrunModel = new ResultMessage(); sRetrunModel.ErrorType = 0; sRetrunModel.MessageContent = "旧密码有误."; return(Json(sRetrunModel)); } string iNewPassword = HashEncrypt.BgPassWord(szNewPassword); bool isFlag = cBll.ChangePassword(item.UserID, iNewPassword); if (isFlag) { var sRetrunModel = new ResultMessage(); sRetrunModel.ErrorType = 1; sRetrunModel.MessageContent = "操作成功."; return(Json(sRetrunModel)); } else { var sRetrunModel = new ResultMessage(); sRetrunModel.ErrorType = 0; sRetrunModel.MessageContent = "操作失败."; return(Json(sRetrunModel)); } }