src/Controller/DefaultController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Util\TargetPathTrait;
  8. class DefaultController extends AbstractController
  9. {
  10.     use TargetPathTrait;
  11.     /**
  12.      * @Route("/", name="homepage")
  13.      *
  14.      * @return Response
  15.      */
  16.     public function index(): Response
  17.     {
  18.         if ($this->isGranted('ROLE_BACKEND_USER')) {
  19.             return $this->redirectToRoute('admin_homepage');
  20.         }
  21.         if ($this->isGranted('ROLE_CUSTOMER_USER')) {
  22.             return $this->redirectToRoute('client_homepage');
  23.         }
  24.         return $this->render('public/homepage.html.twig');
  25.     }
  26.     /**
  27.      * @Route("/portal", name="portal_redirect")
  28.      *
  29.      * @return RedirectResponse
  30.      */
  31.     public function portal(): RedirectResponse
  32.     {
  33.         if ($this->isGranted('ROLE_BACKEND_USER')) {
  34.             return $this->redirectToRoute('admin_homepage');
  35.         }
  36.         if ($this->isGranted('ROLE_CUSTOMER_USER')) {
  37.             return $this->redirectToRoute('client_homepage');
  38.         }
  39.         return $this->redirectToRoute('security_login');
  40.     }
  41. }