public async Task <PasswordAdto> RegisterPasswordAsync(RegisterPasswordAdto registerPasswordAdto) { using (ITransaction transaction = _transactionManager.Create()) { try { Identity identity = await _createIdentityCommand.ExecuteAsync(); await _registerPasswordCommand.ExecuteAsync(identity, await GetAuthenticationGrantTypePasswordAsync(), new RegisterPasswordCommandDdto { Identifier = registerPasswordAdto.Identifier, Password = registerPasswordAdto.Password, ConfirmPassword = registerPasswordAdto.ConfirmPassword, EmailAddress = registerPasswordAdto.EmailAddress }); await _identityCommandRepository.AddAsync(identity); transaction.Commit(); return(new PasswordAdto { IdentityId = identity.Id }); } catch (DomainValidationRuleException e) { throw new BusinessValidationRuleApplicationException(e.ValidationResult); } } }
public async Task CreateAsync(CreateAdminAuthenticationIdentityAdto createAdminAuthenticationIdentityAdto) { using (ITransaction transaction = _transactionManager.Create()) { try { Identity identity = await _createIdentityCommand.ExecuteAsync(); string tempPassword = $"{String.RandomChar(20)}{String.RandomNumeric(3)}{String.RandomSpecial(3)}"; await _registerPasswordCommand.ExecuteAsync(identity, await GetAuthenticationGrantTypePassword(), new RegisterPasswordCommandDdto { Identifier = createAdminAuthenticationIdentityAdto.EmailAddress, EmailAddress = createAdminAuthenticationIdentityAdto.EmailAddress, Password = tempPassword, ConfirmPassword = tempPassword }); await _commandRepository.AddAsync(identity); await _forgotPasswordCommand.ExecuteAsync(new ForgotPasswordCommandDdto { EmailAddress = createAdminAuthenticationIdentityAdto.EmailAddress }); await _commandRepository.UpdateAsync(identity); await Message.SendAsync(AdminIdentityCreatedMessage.Create(createAdminAuthenticationIdentityAdto.ApplicationName, identity.Id)); transaction.Commit(); } catch (DomainValidationRuleException e) { _logger.LogInformation("Could not create admin identity", e); } } }