Added userAdminCommand
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
ba8cdf81f7
commit
90c84e4a9f
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue