diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 1462bf6..42dae43 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -39,6 +39,7 @@ getEmail()]]> getEmail()]]> + getEmail()]]> diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index b73e855..efbbc4d 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -22,6 +22,8 @@ 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\Email; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Uid\UuidV4; @@ -31,7 +33,7 @@ class RegistrationController extends AbstractController { #[Route('/register', name: 'app_register')] - public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, VerifyEmailHelperInterface $verifyEmailHelper): Response + public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, VerifyEmailHelperInterface $verifyEmailHelper, MailerInterface $mailer): Response { $user = new User(); $form = $this->createForm(RegistrationFormType::class, $user); @@ -60,13 +62,10 @@ public function register(Request $request, UserPasswordHasherInterface $userPass ] ); - // TEMP: REMOVE LATER - $this->addFlash('success', 'Confirm your email at: ' . $signatureComponent->getSignedUrl()); + $this->sendConfirmationEmail($mailer, $signatureComponent->getSignedUrl(), $user->getEmail()); + $this->addFlash('info', 'Please check your mail and confirm your email address!'); - // do anything else you need here, like send an email - //TODO SEND VERIFY MAIL - - return $this->redirectToRoute('app_index'); + return $this->redirectToRoute('app_login'); } return $this->render('registration/register.html.twig', [ @@ -105,8 +104,22 @@ public function verifyUserEmail(Request $request, VerifyEmailHelperInterface $ve } #[Route('/verify/resend', name: 'app_verify_resend_email')] - public function resendVerifyEmail(): Response + public function resendVerifyEmail(Request $request): Response { + //TODO: add form with email field return $this->render('registration/resend_verify_email.html.twig'); } + + private function sendConfirmationEmail(MailerInterface $mailer, string $signedUrl, string $userEmail): void + { + $email = (new Email()) + ->from('sys@stage.accounts.oe-modules.com') + ->to($userEmail) + ->priority(Email::PRIORITY_HIGH) + ->subject('Auth oe-modules.com: please confirm your registration') + ->text('Confirm your email at: ' . $signedUrl) + ->html('

Confirm your email at: ' . $signedUrl . '

'); + + $mailer->send($email); + } } diff --git a/templates/common/_flash_messages.html.twig b/templates/common/_flash_messages.html.twig new file mode 100644 index 0000000..df093e6 --- /dev/null +++ b/templates/common/_flash_messages.html.twig @@ -0,0 +1,18 @@ +{% if app.request.hasPreviousSession %} +
+
+ {% for type, messages in app.flashes %} + {% for message in messages %} + {# Bootstrap alert, see https://getbootstrap.com/docs/5.3/components/alerts/ #} + + {% endfor %} + {% endfor %} +
+
+{% endif %} diff --git a/templates/layout-base.html.twig b/templates/layout-base.html.twig index ff9899a..27ea28d 100644 --- a/templates/layout-base.html.twig +++ b/templates/layout-base.html.twig @@ -104,18 +104,7 @@ {% include 'common/navigation.html.twig' %} {% endblock %} - {% for flash in app.flashes('success') %} -
- {{ flash }} -
- {% endfor %} - {% for flash in app.flashes('error') %} -
- {{ flash }} -
- {% endfor %} - - + {% include 'common/_flash_messages.html.twig' %} {% block main %}
diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig index 2b98bcc..1ad62b2 100644 --- a/templates/security/login.html.twig +++ b/templates/security/login.html.twig @@ -33,6 +33,9 @@ {% block body %}
+ + {% include 'common/_flash_messages.html.twig' %} +
{# #}

Please sign in