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

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

            var accountIsNotConfirmedVerificationResult = _accountVerificationService.VerifyAccountIsNotConfirmed(getAccountResult.Value.Confirmed);

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

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

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

            getAccountResult.Value.Confirm(Guid.NewGuid());
            await _communicationBus.DispatchDomainEventsAsync(getAccountResult.Value, cancellationToken);

            await _accountRepository.UpdateAsync(getAccountResult.Value);
        }
Example #2
0
        public void VerifyAccountIsNotConfirmed_Should_Return_VerificationResult_With_Success_True()
        {
            var account = Account.Builder()
                          .SetId(Guid.NewGuid())
                          .SetEmail("*****@*****.**")
                          .SetConfirmed(false)
                          .SetPasswordHash("PasswordHash")
                          .SetSecurityStamp(Guid.NewGuid())
                          .SetCreated(DateTimeOffset.UtcNow)
                          .SetRoles(new List <Guid> {
                Guid.NewGuid()
            })
                          .Build();
            var expectedResult = VerificationResult.Ok();

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

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

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

            var accountIsNotConfirmedVerificationResult = _accountVerificationService.VerifyAccountIsNotConfirmed(getAccountResult.Value.Confirmed);

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

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

            await _accountRepository.UpdateAsync(getAccountResult.Value);

            await _accountConfirmationRequestService.PublishAccountConfirmationRequestedIntegrationEventAsync(getAccountResult.Value.Email, token.Value, correlationId);
        }