2025-12-11 17:22:26 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Service\Mailer;
|
|
|
|
|
|
|
|
|
|
use App\Service\Mailer\Event\CreatedAdminEvent;
|
|
|
|
|
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
|
|
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
|
|
|
|
|
|
#[AsEventListener(event: CreatedAdminEvent::class, method: 'onAdminEvent')]
|
|
|
|
|
class MailerSubscriber
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly UrlGeneratorInterface $urlGenerator,
|
|
|
|
|
private readonly Mailer $mailer
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function onAdminEvent(CreatedAdminEvent $createdAdminEvent): void
|
|
|
|
|
{
|
|
|
|
|
$account = $createdAdminEvent->getAccount();
|
|
|
|
|
$password = $createdAdminEvent->getPassword();
|
|
|
|
|
|
|
|
|
|
$this->mailer->send(
|
|
|
|
|
$account->getEmail(),
|
|
|
|
|
$account->getUsername(),
|
2026-01-15 18:04:01 +01:00
|
|
|
"[LudikEvent] - Création d'un compte administrateur",
|
2025-12-11 17:22:26 +01:00
|
|
|
"mails/new_admin.twig",
|
|
|
|
|
[
|
|
|
|
|
'username' => $account->getUsername(),
|
|
|
|
|
'password' => $password,
|
|
|
|
|
'url' => $this->urlGenerator->generate('app_home'),
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|