Exemple #1
0
        public void VerifyAccountToken_Should_Return_VerificationResult_With_Success_True()
        {
            const string tokenValue = "12345";
            var          token      = Token.Builder()
                                      .SetIssued(DateTimeOffset.UtcNow)
                                      .SetExpires(DateTimeOffset.UtcNow.AddDays(1))
                                      .SetType(TokenTypeEnumeration.AccountConfirmation)
                                      .SetValue(tokenValue)
                                      .Build();
            var expectedResult = VerificationResult.Ok();

            var result = _accountVerificationService.VerifyConfirmationCode(token, tokenValue);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #2
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);
        }