src/Controller/SecurityController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. /**
  8.  * classe qui gere la vue sur l'autenthication des utilisateurs.
  9.  */
  10. class SecurityController extends AbstractController
  11. {
  12.     /**
  13.      * @param AuthenticationUtils $authenticationUtils l'utilitaire d'authentification
  14.      * @return Response Soit une redirection si l'utilisateur est deja loggĂ©, soit la page de login
  15.      */
  16.     #[Route(path'/login'name'app_login')]
  17.     public function login(AuthenticationUtils $authenticationUtils): Response
  18.     {
  19.         if ($this->getUser() !== null) {
  20.             switch($this->getUser()->getRoles()[0]){
  21.             case 'ROLE_ADMIN':
  22.                 return $this->redirectToRoute('admin');
  23.             case 'ROLE_CUSTOMER':
  24.                 return $this->redirectToRoute('customer');
  25.             case 'ROLE_PROVIDER':
  26.                 return $this->redirectToRoute('provider');
  27.             case 'ROLE_GESTIONNAIRE':
  28.                 return $this->redirectToRoute('admin_exporter_home');
  29.             } 
  30.         }
  31.         // get the login error if there is one
  32.         $error $authenticationUtils->getLastAuthenticationError();
  33.         // last username entered by the user
  34.         $lastUsername $authenticationUtils->getLastUsername();
  35.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  36.     }
  37.     #[Route(path'/logout'name'app_logout')]
  38.     public function logout()
  39.     {
  40.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  41.     }
  42. }