Exemple #1
0
        public async Task HandleAsync(RequestPasswordResetTokenCommand command, CancellationToken cancellationToken = default)
        {
            var getAccountResult = await _accountGetterService.GetByEmailAsync(command.Email);

            if (!getAccountResult.Success)
            {
                throw new ValidationException(getAccountResult.Errors);
            }

            var accountIsConfirmedVerificationResult = _accountVerificationService.VerifyAccountIsConfirmed(getAccountResult.Value.Confirmed);

            if (!accountIsConfirmedVerificationResult.Success)
            {
                throw new ValidationException(accountIsConfirmedVerificationResult.Errors);
            }

            var passwordIsSetVerificationResult = _accountVerificationService.VerifyPasswordIsSet(getAccountResult.Value.PasswordHash);

            if (!passwordIsSetVerificationResult.Success)
            {
                throw new ValidationException(passwordIsSetVerificationResult.Errors);
            }

            var correlationId = Guid.NewGuid();
            var token         = getAccountResult.Value.GenerateToken(TokenTypeEnumeration.PasswordReset, correlationId);
            await _communicationBus.DispatchDomainEventsAsync(getAccountResult.Value, cancellationToken);

            await _accountRepository.UpdateAsync(getAccountResult.Value);

            await _passwordResetTokenRequestService.PublishPasswordResetRequestedIntegrationEventAsync(getAccountResult.Value.Email, token.Value, correlationId);
        }
Exemple #2
0
        public void VerifyAccountIsConfirmed_Should_Return_VerificationResult_With_Success_True()
        {
            var account = Account.Builder()
                          .SetId(Guid.NewGuid())
                          .SetEmail("*****@*****.**")
                          .SetConfirmed(true)
                          .SetPasswordHash("PasswordHash")
                          .SetSecurityStamp(Guid.NewGuid())
                          .SetCreated(DateTimeOffset.UtcNow)
                          .SetRoles(new List <Guid> {
                Guid.NewGuid()
            })
                          .Build();
            var expectedResult = VerificationResult.Ok();

            var result = _accountVerificationService.VerifyAccountIsConfirmed(account.Confirmed);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #3
0
        public async Task HandleAsync(ResetPasswordCommand command, CancellationToken cancellationToken = default)
        {
            var getAccountResult = await _accountGetterService.GetByEmailAsync(command.Email);

            if (!getAccountResult.Success)
            {
                throw new ValidationException(getAccountResult.Errors);
            }

            var accountIsConfirmedVerificationResult = _accountVerificationService.VerifyAccountIsConfirmed(getAccountResult.Value.Confirmed);

            if (!accountIsConfirmedVerificationResult.Success)
            {
                throw new ValidationException(accountIsConfirmedVerificationResult.Errors);
            }

            var passwordIsSetVerificationResult = _accountVerificationService.VerifyPasswordIsSet(getAccountResult.Value.PasswordHash);

            if (!passwordIsSetVerificationResult.Success)
            {
                throw new ValidationException(passwordIsSetVerificationResult.Errors);
            }

            var passwordResetToken = getAccountResult.Value.Tokens.SingleOrDefault(x => Equals(x.Type, TokenTypeEnumeration.PasswordReset));
            var confirmationCodeVerificationResult = _accountVerificationService.VerifyConfirmationCode(passwordResetToken, command.Code);

            if (!confirmationCodeVerificationResult.Success)
            {
                throw new ValidationException(confirmationCodeVerificationResult.Errors);
            }

            getAccountResult.Value.ChangePassword(_passwordService.HashPassword(command.Password), Guid.NewGuid());
            await _communicationBus.DispatchDomainEventsAsync(getAccountResult.Value, cancellationToken);

            await _accountRepository.UpdateAsync(getAccountResult.Value);
        }