From 588fb57299134cb52d0b2402dd25aa06329430dd Mon Sep 17 00:00:00 2001 From: Lang <7system7@gmail.com> Date: Wed, 15 Apr 2026 20:19:29 +0200 Subject: [PATCH] new: usr: add notification email when a user is registered #4 --- src/Controller/SecurityController.php | 24 ++++- .../user_registration_notification.html.twig | 93 +++++++++++++++++++ 2 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 templates/emails/user_registration_notification.html.twig diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index b5c8e20..c66bf0b 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -19,6 +19,7 @@ use DateTime; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; @@ -41,6 +42,12 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; #[AsController] class SecurityController extends AbstractController { + public function __construct( + #[Autowire(env: 'APP_CONTACT_MAIL_ADDRESS')] + private readonly string $appContactMailAddress, + ) { + } + #[Route('/login', name: 'MineSeekerBundle_login')] public function login(AuthenticationUtils $authenticationUtils): Response { @@ -92,7 +99,7 @@ class SecurityController extends AbstractController UrlGeneratorInterface::ABSOLUTE_URL, ); - // Ensure HTTPS scheme in production + /** Ensure HTTPS scheme in production */ if ($this->getParameter('kernel.environment') === 'prod') { $activationUrl = str_replace('http://', 'https://', $activationUrl); } @@ -109,6 +116,19 @@ class SecurityController extends AbstractController ]) ); + /** Send admin notification about new user registration */ + $mailer->send( + new TemplatedEmail() + ->from('noreply@mineseeker.hu') + ->to($this->appContactMailAddress) + ->subject('🎉 New User Registration: ' . $user->getUsername()) + ->htmlTemplate('emails/user_registration_notification.html.twig') + ->context([ + 'user' => $user, + 'registeredAt' => new DateTime(), + ]) + ); + $this->addFlash('verify_email', $user->getEmail()); return $this->redirectToRoute('MineSeekerBundle_register'); @@ -148,7 +168,7 @@ class SecurityController extends AbstractController UrlGeneratorInterface::ABSOLUTE_URL, ); - // Ensure HTTPS scheme in production + /** Ensure HTTPS scheme in production */ if ($this->getParameter('kernel.environment') === 'prod') { $resetUrl = str_replace('http://', 'https://', $resetUrl); } diff --git a/templates/emails/user_registration_notification.html.twig b/templates/emails/user_registration_notification.html.twig new file mode 100644 index 0000000..7a166dd --- /dev/null +++ b/templates/emails/user_registration_notification.html.twig @@ -0,0 +1,93 @@ + + + + + New User Registration + + + +
+

👤 New User Registration

+
+
+
+
Username
+
+ {{ user.username }} +
+
+ +
+
Email
+ +
+ +
+
Details
+
+ Registered: {{ registeredAt|date('Y-m-d H:i:s') }}
+ Status: {% if user.isVerified %}✓ Verified{% else %}⏳ Awaiting Email Verification{% endif %}
+ Email Verified: {% if user.isVerified %}Yes{% else %}No - activation link sent{% endif %} +
+
+ + +
+ + +