src/Controller/MainController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  11. /**
  12.  * @IsGranted("ROLE_USER")
  13.  */
  14.  
  15. class MainController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", name="app_index")
  19.      */
  20.     public function index(Session $session)
  21.     {
  22.         $utilisateur $this->getUser();
  23.         
  24.         //vérification des droits.
  25.         if($utilisateur && in_array('ROLE_USER'$utilisateur->getRoles())){
  26.             return $this->redirectToRoute('app_switch', [], Response::HTTP_SEE_OTHER);
  27.         } 
  28.         return $this->redirectToRoute('app_login');
  29.     }
  30.     
  31.     /**
  32.      * @Route("/switch", name="app_switch")
  33.      * 
  34.      */
  35.     public function switch()
  36.     {
  37.         return $this->render('switch_body.html.twig', [
  38.             'controller_name' => 'MainController',
  39.         ]);
  40.     }
  41. }