private TwoFactorAuthenticationIdentity( Identity identity, CreateTwoFactorAuthenticationIdentityDdto createTwoFactorAuthenticationIdentityDdto) { Identity = identity; EmailAddress = createTwoFactorAuthenticationIdentityDdto.EmailAddress; TwoFactorAuthenticationType = createTwoFactorAuthenticationIdentityDdto.TwoFactorAuthenticationType; Token = String.Random(40); TokenExpiry = Instant.Add(Clock.Now(), Duration.FromMinutes(20)); }
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); } } }