Skip to content

Commit c333bdb

Browse files
committed
After review 3
1 parent 333eade commit c333bdb

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Domain/Identity/Command/ImportDefaultsCommand.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
use PhpList\Core\Domain\Identity\Service\AdministratorManager;
1212
use Symfony\Component\Console\Attribute\AsCommand;
1313
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Component\Console\Helper\QuestionHelper;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Question\Question;
1618

1719
#[AsCommand(
1820
name: 'phplist:defaults:import',
@@ -36,14 +38,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3638
$login = self::DEFAULT_LOGIN;
3739
$email = self::DEFAULT_EMAIL;
3840
$envPassword = getenv('PHPLIST_ADMIN_PASSWORD');
39-
$password = is_string($envPassword) && trim($envPassword) !== ''
40-
? $envPassword
41-
: self::DEFAULT_LOGIN;
41+
$envPassword = is_string($envPassword) && trim($envPassword) !== '' ? $envPassword : null;
4242

4343
$allPrivileges = $this->allPrivilegesGranted();
4444

4545
$existing = $this->administratorRepository->findOneBy(['loginName' => $login]);
4646
if ($existing === null) {
47+
// If creating the default admin, require a password. Prefer env var, else prompt for input.
48+
$password = $envPassword;
49+
if ($password === null) {
50+
/** @var QuestionHelper $helper */
51+
$helper = $this->getHelper('question');
52+
$question = new Question('Enter password for default admin (login "admin"): ');
53+
$question->setHidden(true);
54+
$question->setHiddenFallback(false);
55+
$password = (string) $helper->ask($input, $output, $question);
56+
if (trim($password) === '') {
57+
$output->writeln('<error>Password must not be empty.</error>');
58+
return Command::FAILURE;
59+
}
60+
}
61+
4762
$dto = new CreateAdministratorDto(
4863
loginName: $login,
4964
password: $password,

0 commit comments

Comments
 (0)