From 2c9511ecf41764e29cb788009aebe33caa2350b6 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Tue, 2 Jul 2024 01:41:47 -0400 Subject: [PATCH] migrate email to use Util class and method --- src/Controller/RegistrationController.php | 27 +++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index dcb2fef..b1a8a87 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -4,18 +4,25 @@ namespace App\Controller; use App\Entity\User; use App\Form\RegistrationFormType; +use App\Utils\Utils; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Address; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Routing\Attribute\Route; class RegistrationController extends AbstractController { #[Route('/register', name: 'app_register')] - public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response - { + public function register( + Request $request, + UserPasswordHasherInterface $userPasswordHasher, + EntityManagerInterface $entityManager, + MailerInterface $mailer + ): Response { $user = new User(); $form = $this->createForm(RegistrationFormType::class, $user); @@ -39,6 +46,8 @@ class RegistrationController extends AbstractController $entityManager->persist($user); $entityManager->flush(); + $this->sendEmail($user, $mailer); + return $this->redirectToRoute('app_home'); } @@ -46,4 +55,18 @@ class RegistrationController extends AbstractController 'registrationForm' => $form, ]); } + + private function sendEmail(User $user, MailerInterface $mailer): void + { + $util = new Utils(); + $util->sendEmail( + $mailer, + new Address('ryan@rkprather.com'), + new Address('ryan@rkprather.com'), + 'New Account', + $this->renderView('emails/registration.html.twig', [ + 'user' => $user + ]) + ); + } }