示例#1
0
        public async Task ConfirmIdentityAsync(ConfirmIdentityAdto confirmIdentityAdto)
        {
            using (ITransaction transaction = _transactionManager.Create())
            {
                try
                {
                    Identity identity = await _identityCommandRepository.GetByIdAsync(confirmIdentityAdto.IdentityId);

                    if (identity == null)
                    {
                        throw new BusinessApplicationException(ExceptionType.NotFound, "No identity found to confirm identity");
                    }

                    await _confirmIdentityCommand.ExecuteAsync(identity, new ConfirmIdentityCommandDdto
                    {
                        Token = confirmIdentityAdto.Token
                    });

                    await _identityCommandRepository.UpdateAsync(identity);

                    transaction.Commit();
                }
                catch (InvalidTwoFactorTokenDomainException)
                {
                    throw new BusinessApplicationException(ExceptionType.Unauthorized, "Token invalid for identity");
                }
                catch (DomainValidationRuleException e)
                {
                    throw new BusinessValidationRuleApplicationException(e.ValidationResult);
                }
            }
        }
示例#2
0
        public async Task UpdateAsync(UpdateIdentityClaimAdto updateIdentityClaimAdto)
        {
            using (ITransaction transaction = _transactionManager.Create())
            {
                try
                {
                    Identity identity = await _commandRepository.GetByIdAsync(updateIdentityClaimAdto.IdentityId);

                    if (identity == null)
                    {
                        throw new BusinessApplicationException(ExceptionType.NotFound, $"Identity with id: {updateIdentityClaimAdto.IdentityId} does not exist");
                    }

                    await _addOrChangeIdentityClaimCommand.ExecuteAsync(identity, new AddOrChangeIdentityClaimCommandDdto
                    {
                        Type  = updateIdentityClaimAdto.Type,
                        Value = updateIdentityClaimAdto.Value
                    });

                    await _commandRepository.UpdateAsync(identity);

                    transaction.Commit();
                }
                catch (DomainValidationRuleException e)
                {
                    _logger.LogInformation("Could not add identity claim", e);
                }
            }
        }