🐛 fix(mailer): Corrige l'URL de suivi du mail pour production. ✨ feat(account): Ajoute la gestion de l'avatar de l'utilisateur. ✨ feat(account): Ajoute la gestion du premier mot de passe à la connexion. 🗑️ refactor: Supprime les tests unitaires obsolètes.
58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use App\Entity\Account;
|
|
use App\Service\Generator\TempPasswordGenerator;
|
|
use App\Service\Mailer\Event\CreatedAdminEvent;
|
|
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\Console\Question\Question;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
use Symfony\Component\Uid\Uuid;
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
|
|
|
#[AsCommand(name: 'mainframe:admin')]
|
|
class AccountCommand extends Command
|
|
{
|
|
public function __construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly UserPasswordHasherInterface $userPasswordHasher, private readonly EntityManagerInterface $entityManager, ?string $name = null)
|
|
{
|
|
parent::__construct($name);
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
$io->title("Création d'un utilisateur administrateur");
|
|
|
|
$userExit = $this->entityManager->getRepository(Account::class)->findOneBy(['email'=>'jovann@siteconseil.fr']);
|
|
if(!$userExit instanceof Account) {
|
|
$password = TempPasswordGenerator::generate();
|
|
$userExit = new Account();
|
|
$userExit->setRoles(['ROLE_ROOT']);
|
|
$userExit->setUuid(Uuid::v4());
|
|
$userExit->setIsFirstLogin(true);
|
|
|
|
$questionEmail = new Question("Email ?");
|
|
$email = $io->askQuestion($questionEmail);
|
|
|
|
$userExit->setEmail($email);
|
|
|
|
$questionUsername = new Question("Username ?");
|
|
$username = $io->askQuestion($questionUsername);
|
|
$userExit->setUsername($username);
|
|
$userExit->setPassword($this->userPasswordHasher->hashPassword($userExit, $password));
|
|
|
|
$this->entityManager->persist($usserExit);
|
|
$this->entityManager->flush();
|
|
$this->eventDispatcher->dispatch(new CreatedAdminEvent($userExit, $password));
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|