public void ForgotUserPasswordCommandHandler_Does_Nothing_For_Nonexistent_User() { var handler = new ForgotUserPasswordCommandHandler(_repository, _mailClient, new PasswordResetMailTemplate(_appSettings)); var command = new ForgotUserPasswordCommand("*****@*****.**"); var result = handler.Execute(command); result.Success.Should().BeTrue(); _mailClient.SentMessages.Should().BeEmpty(); }
public async Task ForgotPasswordAsync(ForgotUserPasswordCommand command) { if (NotifyCommandErrors(command)) { return; } NutrientIdentityUser user = await _userManager.FindByEmailAsync(command.Email); if (!NotifyNullUser(user, command.Email)) { await SendAccountPasswordResetEmailAsync(user); } }
public void ForgotUserPasswordCommandHandler_Succeeds() { var handler = new ForgotUserPasswordCommandHandler(_repository, _mailClient, new PasswordResetMailTemplate(_appSettings)); var command = new ForgotUserPasswordCommand("*****@*****.**"); var user = Substitute.For <User>(); user.Email.Returns("*****@*****.**"); user.Password.Returns(new Password("test")); user.Status.Returns(UserStatus.Active); _context.Users.Add(user); var result = handler.Execute(command); result.Success.Should().BeTrue(); user.Received().GeneratePasswordResetToken(); user.DidNotReceive().PasswordResetRequestFailed(); }
public void ForgotUserPasswordCommandHandler_Sends_Email() { var handler = new ForgotUserPasswordCommandHandler(_repository, _mailClient, new PasswordResetMailTemplate(_appSettings)); var command = new ForgotUserPasswordCommand("*****@*****.**"); var user = Substitute.For <User>(); user.Email.Returns("*****@*****.**"); user.Password.Returns(new Password("test")); user.Status.Returns(UserStatus.Active); _context.Users.Add(user); handler.Execute(command); _mailClient.SentMessages.Should().HaveCount(1); _mailClient.SentMessages[0].Subject.Should().Be("Your password reset request"); _mailClient.SentMessages[0].To.Should().Be("*****@*****.**"); }
public async Task ForgotPassword(ForgotUserPasswordCommand command) { command.Validate(); if (AddNotifications(command)) { return; } LedgerIdentityUser user = await GetByEmail(command.Email); if (NotifyNullUser(user)) { return; } string resetToken = await _userManager.GeneratePasswordResetTokenAsync(user); await PublishLocal(new UserForgotPasswordEvent(user.Email, resetToken)); }
public async Task <IActionResult> ForgotPassword([FromBody] ForgotUserPasswordCommand command) { await _userApplicationService.ForgotPassword(command); return(CreateResponse()); }
public ActionResult ForgotPassword(ForgotUserPasswordCommand command) { command.Token = Guid.NewGuid().ToString().Replace("-", string.Empty); command.ChangePasswordUrl = Url.Action("ChangePassword", "Account", AnonymousHelper.ToDictionary(new { ResetToken = command.Token }), "http", Request.Url.DnsSafeHost); return(TryPush(command, setting => setting.SuccessResult = () => RedirectToAction("LandingAjax", "Notification", new { type = "success", message = "Your new password sent to you by e-mail" }))); }
public async Task <IActionResult> ForgotPasswordAsync([FromBody] ForgotUserPasswordCommand command) { await _accountService.ForgotPasswordAsync(command); return(CreateResponse()); }