From 0ead23e06336387c60b1cfe10074467c62e27cb7 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 6 Sep 2018 20:33:54 +0200 Subject: [PATCH] Optimized login messages --- application/src/Controller/SecurityController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/application/src/Controller/SecurityController.php b/application/src/Controller/SecurityController.php index fc36d14..ef678b4 100644 --- a/application/src/Controller/SecurityController.php +++ b/application/src/Controller/SecurityController.php @@ -5,6 +5,7 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Translation\TranslatorInterface; /** * @@ -17,13 +18,16 @@ class SecurityController extends AbstractController * * @Route("/login", name="login") */ - public function login(AuthenticationUtils $authenticationUtils): Response + public function login(AuthenticationUtils $authenticationUtils,TranslatorInterface $translator): Response { $error = $authenticationUtils->getLastAuthenticationError(); if ($error) { $this->addFlash('danger', $error->getMessage()); }else{ - $this->addFlash('success', "User loged in."); + $lastUsername = $authenticationUtils->getLastUsername(); + if($lastUsername){ + $this->addFlash('success', $translator->trans('User %user% loged in.',['user'=>$lastUsername])); + } } $this->addFlash('info', $authenticationUtils->getLastUsername()); return $this->render("user/login.html.twig",[