src/Controller/SecurityController.php line 15

  1. <?php
  2. namespace App\Controller;
  3. use Exception;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController
  10. {
  11.     #[Route('/login'name'login')]
  12.     public function login(AuthenticationUtils $authenticationUtils): Response
  13.     {
  14.         $error $authenticationUtils->getLastAuthenticationError();
  15.         $lastUsername $authenticationUtils->getLastUsername();
  16.         if ($this->getUser()) {
  17.             return $this->redirect($this->generateUrl('app_gestion_dashboard_index'));
  18.         }
  19.         return $this->render('user/login.html.twig', [
  20.             'controller_name' => 'UserController',
  21.             'last_username' => $lastUsername,
  22.             'error' => $error,
  23.         ]);
  24.     }
  25.     /**
  26.      * @throws Exception
  27.      */
  28.     #[Route('/logout'name'logout')]
  29.     public function logout(): void
  30.     {
  31.         throw new AccessDeniedException('Bye');
  32.     }
  33. }