<?php
namespace App\Controller;
use App\Enum\Role;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
class HomeController extends AbstractController
{
#[Route('/', name: 'app_home')]
public function index(Request $request, RouterInterface $router): RedirectResponse
{
$user = $this->getUser();
if (!$user) {
// login olmamışsa login sayfasına gönder
return $this->redirectToRoute('app_login');
}
$roles = $user->getRoles();
if (in_array(Role::ROLE_ADMIN->getSymfonyRole(), $roles, true)) {
return $this->redirectToRoute('app_panel_dashboard');
}
if (in_array(Role::ROLE_SALES_REP->getSymfonyRole(), $roles, true)) {
return $this->redirectToRoute('seller_dashboard');
}
if (in_array(Role::ROLE_ACCOUNTING->getSymfonyRole(), $roles, true)) {
return $this->redirectToRoute('accounting_dashboard');
}
return $this->redirectToRoute('app_logout');
}
}