Added userAdminCommand
testing/ogcore-api/pipeline/head This commit looks good Details

pull/21/head
Manuel Aranda Rosales 2025-03-03 09:14:00 +01:00
parent ba8cdf81f7
commit 90c84e4a9f
1 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\Menu;
use App\Entity\User;
use App\Model\UserGroupPermissions;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
#[AsCommand(name: 'opengnsys:load-default-user', description: 'Load the default user')]
class LoadDefaultUserAdminCommand extends Command
{
CONST string PLAIN_PASSWORD = '12345678';
const string USERNAME = 'ogadmin';
public function __construct(
private readonly EntityManagerInterface $entityManager
)
{
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$factory = new PasswordHasherFactory([
'auto' => ['algorithm' => 'auto'],
]);
$hasher = $factory->getPasswordHasher('auto');
$hash = $hasher->hash(self::PLAIN_PASSWORD);
$user = new User();
$user->setUsername(self::USERNAME);
$user->setRoles([UserGroupPermissions::ROLE_SUPER_ADMIN]);
$user->setPassword($hash);
$this->entityManager->persist($user);
$this->entityManager->flush();
return Command::SUCCESS;
}
}