src/Controller/SecurityController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Security\Core\Security;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  9. class SecurityController extends AbstractController
  10. {
  11.     #[Route(path'/connexion'name'app_login')]
  12.     public function login(AuthenticationUtils $authenticationUtils,Security $security): Response
  13.     {
  14.         // Rediriger uniquement si l'utilisateur est complètement authentifié
  15.         if ($security->getUser() && $security->isGranted('ROLE_ADMIN')) {
  16.             return $this->redirectToRoute('app_dashboard');
  17.         } 
  18.         
  19.         if ($security->getUser() && $security->isGranted('ROLE_MAGASINIER')) {
  20.             return $this->redirectToRoute('app_menu_index');
  21.         }
  22.         
  23.         if ($security->getUser() && $security->isGranted('ROLE_SUPER_ADMIN')) {
  24.             return $this->redirectToRoute('app_dashboard');
  25.         }
  26.         // get the login error if there is one
  27.         $error $authenticationUtils->getLastAuthenticationError();
  28.         // last username entered by the user
  29.         $lastUsername $authenticationUtils->getLastUsername();
  30.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  31.     }
  32.     #[Route(path'/logout'name'app_logout')]
  33.     public function logout(): void
  34.     {
  35.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  36.     }
  37.    
  38. }