public async Task <IActionResult> ForgotPasswordViaEmail(ForgotPasswordViaEmailViewModel model) { var mail = await _dbContext.UserEmails.SingleOrDefaultAsync(t => t.EmailAddress == model.Email.ToLower()); if (mail == null) { return(NotFound()); } var user = await _dbContext .Users .Include(t => t.Emails) .SingleOrDefaultAsync(t => t.Id == mail.OwnerId); var code = await _userManager.GeneratePasswordResetTokenAsync(user); // limit the sending frenquency to 3 minutes. if (DateTime.UtcNow > mail.LastSendTime + new TimeSpan(0, 1, 0)) { mail.LastSendTime = DateTime.UtcNow; await _dbContext.SaveChangesAsync(); _cannonService.FireAsync <ConfirmationEmailSender>(async(sender) => { await sender.SendResetPassword(code, user.Id, mail.EmailAddress); }); } return(RedirectToAction(nameof(ForgotPasswordSent))); }
public async Task <IActionResult> ForgotPasswordViaSms(ForgotPasswordViaEmailViewModel model) { var mail = await _dbContext.UserEmails.SingleOrDefaultAsync(t => t.EmailAddress == model.Email.ToLower()); if (mail == null) { return(NotFound()); } var user = await _dbContext .Users .Include(t => t.Emails) .SingleOrDefaultAsync(t => t.Id == mail.OwnerId); if (user.PhoneNumberConfirmed == false) { return(NotFound()); } var code = StringOperation.RandomString(6); user.SMSPasswordResetToken = code; await _userManager.UpdateAsync(user); _cannonService.FireAsync <APISMSSender>(async(sender) => { await sender.SendAsync(user.PhoneNumber, code + " is your Aiursoft password reset code."); }); return(RedirectToAction(nameof(EnterSmsCode), new { model.Email })); }
public async Task <IActionResult> ForgotPasswordViaSMS(ForgotPasswordViaEmailViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { model.ModelStateValid = false; ModelState.AddModelError("", $"We can't find an account with email:`{model.Email}`!"); return(View(model)); } if (user.PhoneNumberConfirmed == false) { model.ModelStateValid = false; ModelState.AddModelError("", "Your account did not bind a valid phone number!"); return(View(model)); } var code = StringOperation.RandomString(6); user.SMSPasswordResetToken = code; await _userManager.UpdateAsync(user); await _smsSender.SendAsync(user.PhoneNumber, code + " is your Aiursoft password reset code."); return(RedirectToAction(nameof(EnterSMSCode), new { model.Email })); } return(View(model)); }
public async Task <IActionResult> ForgotPasswordViaEmail(ForgotPasswordViaEmailViewModel model) { var mail = await _dbContext.UserEmails.SingleOrDefaultAsync(t => t.EmailAddress == model.Email.ToLower()); if (mail == null) { return(NotFound()); } var user = await _dbContext .Users .Include(t => t.Emails) .SingleOrDefaultAsync(t => t.Id == mail.OwnerId); var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = new AiurUrl(_serviceLocation.API, "User", nameof(ResetPassword), new { Code = code, UserId = user.Id }); await _emailSender.SendEmail(model.Email, "Reset Password", $"Please reset your password by clicking <a href='{callbackUrl}'>here</a>"); return(RedirectToAction(nameof(ForgotPasswordSent))); }
public async Task<IActionResult> ForgotPasswordViaSMS(ForgotPasswordViaEmailViewModel model) { var mail = await _dbContext.UserEmails.SingleOrDefaultAsync(t => t.EmailAddress == model.Email.ToLower()); if (mail == null) { return NotFound(); } var user = await _userManager.FindByIdAsync(mail.OwnerId); if (user.PhoneNumberConfirmed == false) { return NotFound(); } var code = StringOperation.RandomString(6); user.SMSPasswordResetToken = code; await _userManager.UpdateAsync(user); await _smsSender.SendAsync(user.PhoneNumber, code + " is your Aiursoft password reset code."); return RedirectToAction(nameof(EnterSMSCode), new { model.Email }); }
public async Task <IActionResult> ForgotPasswordViaEmail(ForgotPasswordViaEmailViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { return(RedirectToAction(nameof(ForgotPasswordSent))); } var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = new AiurUrl(Values.ApiServerAddress, "User", nameof(ResetPassword), new { Code = code, UserId = user.Id }); await _emailSender.SendEmail(model.Email, "Reset Password", $"Please reset your password by clicking <a href='{callbackUrl}'>here</a>"); return(RedirectToAction(nameof(ForgotPasswordSent))); } return(View(model)); }
public IActionResult ForgotPasswordViaSMS() { var model = new ForgotPasswordViaEmailViewModel(); return(View(model)); }