SecurityController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Attribute\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. class SecurityController extends AbstractController
  8. {
  9. #[Route(path: '/login', name: 'app_login')]
  10. public function login(AuthenticationUtils $authenticationUtils): Response
  11. {
  12. // get the login error if there is one
  13. $error = $authenticationUtils->getLastAuthenticationError();
  14. // last username entered by the user
  15. $lastUsername = $authenticationUtils->getLastUsername();
  16. // Gestion des erreurs par flash messages
  17. if ($error) {
  18. $this->addFlash('danger', $error->getMessage());
  19. }
  20. return $this->render('security/login.html.twig', [
  21. 'last_username' => $lastUsername,
  22. 'account_creation' => strtolower($_ENV['APP_ALLOW_REGISTER'])
  23. ]);
  24. }
  25. #[Route(path: '/logout', name: 'app_logout')]
  26. public function logout(): void
  27. {
  28. throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  29. }
  30. }