/// <summary> /// 重置密码 /// </summary> public ActionResult ResetPwd() { string v = WebHelper.GetQueryString("v"); //解密字符串 string realV; try { realV = MallUtils.AESDecrypt(v); } catch (Exception ex) { //如果v来自邮件,那么需要url解码 realV = MallUtils.AESDecrypt(WebHelper.UrlDecode(v)); } //数组第一项为uid,第二项为验证时间,第三项为随机值 string[] result = StringHelper.SplitString(realV); if (result.Length != 3) { return(HttpNotFound()); } int uid = TypeHelper.StringToInt(result[0]); DateTime time = TypeHelper.StringToDateTime(result[1]); PartUserInfo partUserInfo = Users.GetPartUserById(uid); if (partUserInfo == null) { return(PromptView("用户不存在")); } //判断验证时间是否过时 if (DateTime.Now.AddMinutes(-30) > time) { return(PromptView("此链接已经失效,请重新验证")); } //get请求 if (WebHelper.IsGet()) { ResetPwdModel model = new ResetPwdModel(); model.V = v; return(View(model)); } //ajax请求 string password = WebHelper.GetFormString("password"); string confirmPwd = WebHelper.GetFormString("confirmPwd"); StringBuilder errorList = new StringBuilder("["); //验证 if (string.IsNullOrWhiteSpace(password)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码不能为空", "}"); } else if (password.Length < 4 || password.Length > 32) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码必须大于3且不大于32个字符", "}"); } else if (password != confirmPwd) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "confirmPwd", "两次输入的密码不一样", "}"); } if (errorList.Length == 1) { //生成用户新密码 string p = Users.CreateUserPassword(password, partUserInfo.Salt); //设置用户新密码 Users.UpdateUserPasswordByUid(uid, p); //清空当前用户信息 WebHelper.DeleteCookie("bma"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); return(AjaxResult("success", Url.Action("login"))); } else { return(AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true)); } }