<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
/**
* @IsGranted("ROLE_USER")
*/
class MainController extends AbstractController
{
/**
* @Route("/", name="app_index")
*/
public function index(Session $session)
{
$utilisateur = $this->getUser();
//vérification des droits.
if($utilisateur && in_array('ROLE_USER', $utilisateur->getRoles())){
return $this->redirectToRoute('app_switch', [], Response::HTTP_SEE_OTHER);
}
return $this->redirectToRoute('app_login');
}
/**
* @Route("/switch", name="app_switch")
*
*/
public function switch()
{
return $this->render('switch_body.html.twig', [
'controller_name' => 'MainController',
]);
}
}