src/Controller/RootController.php line 12

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. class RootController extends AbstractController
  7. {
  8.     #[Route('/', name: 'app_root')]
  9.     public function index(): Response
  10.     {
  11.         $user = $this->getUser();
  12.         if ($user != null ){
  13.             $roles = $user->getRoles();
  14.             if( in_array('ROLE_ADMIN', $roles) ) {
  15.                 return $this->redirectToRoute('admin');
  16.             } else {
  17.                 return $this->redirectToRoute('app_association');
  18.             }
  19.         } else {
  20.             return $this->redirectToRoute('app_login');
  21.         }
  22.         
  23.     }
  24. }