Skip to content

Commit d24769b

Browse files
committed
feat: add default admin password configuration and update ImportDefaultsCommand
1 parent 8d28d3b commit d24769b

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ PHPLIST_DATABASE_USER=phplist
1616
PHPLIST_DATABASE_PASSWORD=phplist
1717
DATABASE_PREFIX=phplist_
1818
LIST_TABLE_PREFIX=listattr_
19+
PHPLIST_ADMIN_PASSWORD=admin
1920

2021
APP_DEV_VERSION=0
2122
APP_DEV_EMAIL=dev@dev.com

config/parameters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ parameters:
1414
database_user: '%env(PHPLIST_DATABASE_USER)%'
1515
database_password: '%env(PHPLIST_DATABASE_PASSWORD)%'
1616
database_prefix: '%env(DATABASE_PREFIX)%'
17+
app.default_admin_password: '%env(PHPLIST_DEFAULT_ADMIN_PASSWORD)%'
1718
list_table_prefix: '%env(LIST_TABLE_PREFIX)%'
1819
app.dev_version: '%env(APP_DEV_VERSION)%'
1920
app.dev_email: '%env(APP_DEV_EMAIL)%'

src/Domain/Identity/Command/ImportDefaultsCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
1717
use Symfony\Component\Console\Question\Question;
18+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1819

1920
#[AsCommand(
2021
name: 'phplist:defaults:import',
2122
description: 'Imports default values into the database (e.g., default admin with all privileges).'
2223
)]
2324
class ImportDefaultsCommand extends Command
2425
{
25-
private const DEFAULT_LOGIN = 'admin';
26+
private const DEFAULT_LOGIN = 'test1';
2627
private const DEFAULT_EMAIL = 'admin@example.com';
2728

2829
public function __construct(
2930
private readonly AdministratorRepository $administratorRepository,
3031
private readonly AdministratorManager $administratorManager,
3132
private readonly EntityManagerInterface $entityManager,
33+
#[Autowire('%app.default_admin_password%')]
34+
private readonly string $defaultAdminPassword = ''
3235
) {
3336
parent::__construct();
3437
}
@@ -37,15 +40,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3740
{
3841
$login = self::DEFAULT_LOGIN;
3942
$email = self::DEFAULT_EMAIL;
40-
$envPassword = getenv('PHPLIST_ADMIN_PASSWORD');
41-
$envPassword = is_string($envPassword) && trim($envPassword) !== '' ? $envPassword : null;
43+
$password = $this->defaultAdminPassword !== '' ? $this->defaultAdminPassword : null;
4244

4345
$allPrivileges = $this->allPrivilegesGranted();
4446

4547
$existing = $this->administratorRepository->findOneBy(['loginName' => $login]);
4648
if ($existing === null) {
4749
// If creating the default admin, require a password. Prefer env var, else prompt for input.
48-
$password = $envPassword;
4950
if ($password === null) {
5051
/** @var QuestionHelper $helper */
5152
$helper = $this->getHelper('question');

0 commit comments

Comments
 (0)