migrate email to use Util class and method

This commit is contained in:
Ryan Prather 2024-07-02 01:41:47 -04:00
parent 97d656912c
commit 2c9511ecf4

View File

@ -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
])
);
}
}