src/Controller/HomeController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Enum\Role;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Routing\RouterInterface;
  9. class HomeController extends AbstractController
  10. {
  11.     #[Route('/'name'app_home')]
  12.     public function index(Request $requestRouterInterface $router): RedirectResponse
  13.     {
  14.         $user $this->getUser();
  15.         if (!$user) {
  16.             // login olmamışsa login sayfasına gönder
  17.             return $this->redirectToRoute('app_login');
  18.         }
  19.         $roles $user->getRoles();
  20.         
  21.         if (in_array(Role::ROLE_ADMIN->getSymfonyRole(), $rolestrue)) {
  22.             return $this->redirectToRoute('app_panel_dashboard');
  23.         }
  24.         if (in_array(Role::ROLE_SALES_REP->getSymfonyRole(), $rolestrue)) {
  25.             return $this->redirectToRoute('seller_dashboard');
  26.         }
  27.         if (in_array(Role::ROLE_ACCOUNTING->getSymfonyRole(), $rolestrue)) {
  28.             return $this->redirectToRoute('accounting_dashboard');
  29.         }
  30.         return $this->redirectToRoute('app_logout');
  31.     }
  32. }