public async Task <IActionResult> ForgotPassword(ForgetPassModel forgetPassModel) { var user = await this.userManager.FindByEmailAsync(forgetPassModel.Email); if ((user == null) || (await this.userManager.IsEmailConfirmedAsync(user))) { return(null); } ////send email confirmation var code = await this.userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action( "SendPasswordResetEmail", "ApplicationUser", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await this.emailSender.SendEmailAsync(forgetPassModel.Email, "Reset Password", $"Please reset your password by" + $" clicking this link:<a href='{callbackUrl}'>Link</a>"); return(this.Ok()); }
public ActionResult ForGotPassWord(ForgetPassModel model) { if (ModelState.IsValid) { AccountServices service = new AccountServices(); var info = service.Get(m => m.UserName == model.UserName && m.Tel == model.Tel); if (info == null) { ModelState.AddModelError("UserName", "用户名或手机号错误,请确认"); } else { ValidCodeHelper vCode = new ValidCodeHelper(); string code = vCode.CreateValidateCode(6); var tempass = EncryptHelper.Lower32(code); info.Password = tempass; service.UpdatePassword(info.Id, tempass); new SmsService().SendCode(model.Tel, code); return(Redirect("/Account/Temp")); } } return(View()); }