Added new user admin command
parent
9089224522
commit
aedffb5596
|
@ -0,0 +1,20 @@
|
|||
|
||||
###> symfony/framework-bundle ###
|
||||
APP_ENV=prod
|
||||
APP_SECRET=e95c7f17da15ce1b03d77ad655379c34
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
###> doctrine/doctrine-bundle ###
|
||||
DATABASE_URL="mysql://root:root@ogcore-database:3306/ogcore?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||
OG_1_DATABASE_URL="mysql://root:root@ogcore-database:3306/ogcore_old_og?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
||||
###> nelmio/cors-bundle ###
|
||||
CORS_ALLOW_ORIGIN='*'
|
||||
###< nelmio/cors-bundle ###
|
||||
|
||||
###> lexik/jwt-authentication-bundle ###
|
||||
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
|
||||
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
|
||||
JWT_PASSPHRASE=8b9154df37ffa91ef9186ce095324e39e50ff3b023bb1ed34383abd019ba4515
|
||||
###< lexik/jwt-authentication-bundle ###
|
|
@ -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