Exemple #1
0
        public void VerifyPasswordIsNotSet_Should_Return_VerificationResult_With_Success_True()
        {
            var account = Account.Builder()
                          .SetId(Guid.NewGuid())
                          .SetEmail("*****@*****.**")
                          .SetConfirmed(true)
                          .SetPasswordHash(string.Empty)
                          .SetSecurityStamp(Guid.NewGuid())
                          .SetCreated(DateTimeOffset.UtcNow)
                          .SetRoles(new List <Guid> {
                Guid.NewGuid()
            })
                          .Build();
            var expectedResult = VerificationResult.Ok();

            var result = _accountVerificationService.VerifyPasswordIsNotSet(account.PasswordHash);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #2
0
        public async Task HandleAsync(AssignPasswordCommand command, CancellationToken cancellationToken = default)
        {
            var getAccountResult = await _accountGetterService.GetByIdAsync(command.AccountId);

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

            var passwordIsNotSetVerificationResult = _accountVerificationService.VerifyPasswordIsNotSet(getAccountResult.Value.PasswordHash);

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

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

            await _accountRepository.UpdateAsync(getAccountResult.Value);
        }