From 5f2e7476ff4126bd493cc8823920f14f9d89c8ba Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Sun, 24 Nov 2024 22:19:07 -0500 Subject: [PATCH] Still can't find out why the flash isn't setting and rendering to the page. --- app/src/Controller/User/LoginUserAction.php | 12 +++++++++--- app/templates/layouts/components/flash.twig | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/Controller/User/LoginUserAction.php b/app/src/Controller/User/LoginUserAction.php index 85f1a57..3be71df 100644 --- a/app/src/Controller/User/LoginUserAction.php +++ b/app/src/Controller/User/LoginUserAction.php @@ -27,18 +27,24 @@ class LoginUserAction extends Controller $user = $this->userRepository->getFromEmail($credentials['email']); } catch (EntityNotFoundException $e) { $this->logger->error("Unable to login user."); - $this->session->getFlash()->add('error', "Unable to login user."); + $this->session + ->getFlash() + ->add('error', "Unable to login user."); + return $this->render('user/login.twig')->withStatus(400); } if (!$this->auth->verify($credentials['password'], $user->getPassword())) { $this->logger->error("Unable to verify user password."); - $this->session->getFlash()->add('error', "Unable to login user."); + $this->session + ->getFlash() + ->add('error', "Unable to login user."); + return $this->render('user/login.twig')->withStatus(400); } // start the session - $this->session->getFlash()->add('success', "Successfully loggedin."); + $this->session->getFlash()->add('success', "Successfully logged in."); $this->session->set('user', [ 'id' => $user->getId(), 'authenticated' => true ]); return $this->redirect('/dashboard', 302); } diff --git a/app/templates/layouts/components/flash.twig b/app/templates/layouts/components/flash.twig index 1593c13..fa1989d 100644 --- a/app/templates/layouts/components/flash.twig +++ b/app/templates/layouts/components/flash.twig @@ -1,9 +1,19 @@ +{% for message in flash.get('success') %} +
+ {{ message }} +
+{% endfor %} + {% for message in flash.get('notice') %}
{{ message }}
{% endfor %} +{% if flash.has('error') %} +
Hello!
+{% endif %} + {% for message in flash.get('error') %}
{{ message }}