Optimized login messages

This commit is contained in:
Kevin Frantz 2018-09-06 20:33:54 +02:00
parent cff5afe018
commit 0ead23e063

View File

@ -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",[