public async Task <ActionResult> Verify4ResetPassword(PreVerify4ResetPasswordModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.UserName); if (user == null) { return(RedirectToAction("ForgotPassword")); } //验证身份 var success = false; #region : 验证码验证 var result4VerifyCode = await EmailVerifyCodeProvider.CodeVerify(user.Email, model.VerifyCode, TimeSpan.FromMinutes(30)); if (!result4VerifyCode.Success) { foreach (var err in result4VerifyCode.ErroMessage) { ModelState.AddModelError(err.Key, err.Value); } } else { success = true; } #endregion if (success) { //生成重置密码的Code string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); return(View("ResetPassword", new ResetPasswordModel { Code = code, UserId = user.Id })); //跳转到密码重置} } } return(View(model)); }
public async Task <ActionResult> GetVerifyCode4ResetPassword(string userName, string email) { JsonResultWithErro <bool> resultData = new JsonResultWithErro <bool>(true); var user = await UserManager.FindByNameAsync(userName); if (user != null) { #region 发送验证码 if (!string.IsNullOrEmpty(user.Email)) { var verifyCode = CommonCodeGenerator.Generator(6); var verifyEmail = user.Email; var result4Send = await EmailVerifyCodeProvider.SendCode(verifyCode, verifyEmail, "您的验证码为 "); if (!result4Send.Success) { resultData.Data = false; resultData.StateCode = 101; //加载错误消息 resultData.Message = string.Join(";", result4Send.ErroMessage.Values); } } else { resultData.Data = false; resultData.StateCode = 18; resultData.Message = "您还没有填写邮箱"; } #endregion } else { resultData.Data = false; resultData.StateCode = 20; resultData.Message = "用户不存在,获取验证码失败"; } return(Json(resultData, JsonRequestBehavior.AllowGet)); }