<?php
namespace App\Controller;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request, TranslatorInterface $translator)
{
$user = $this->getUser();
if(!$user)
{
return $this->render('security/login.html.twig', [
'last_username' => null,
'error' => null,
]);
} elseif ($user->getUserStatus()->getId() != 2) {
$this->get('security.token_storage')->setToken(null);
$this->get('session')->invalidate();
return $this->render('security/login.html.twig', [
'last_username' => null,
'error' => null,
]);
}
else {
// replace this example code with whatever you need
if($user->getRole()->getId() == User::ROLE_ADMIN || $user->getRole()->getId() == User::ROLE_SUPER_ADMIN)
{
return $this->redirectToRoute('dashboard_index');
/* return $this->render('dashboard/index.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
]);*/
} elseif ($user->getRole()->getId() == User::ROLE_CUSTOMER) {
if ($user->getCustomer() === null)
{
if (count($user->getUserCustomerList()) >= 1)
{
$user->setCustomer($user->getUserCustomerList()->getValues()[0]->getCustomer());
$em = $this->getDoctrine()->getManager();
$em->flush();
} else {
$this->get('security.token_storage')->setToken(null);
$this->get('session')->invalidate();
$no_customer_supplier = $translator->trans('error.no_customer_supplier');
return $this->render('@Twig/Exception/error.html.twig', [
'status_code' => 500,
'status_text' => $no_customer_supplier,
]);
}
}
return $this->redirectToRoute('dashboard_index_customer');
} else {
return $this->redirectToRoute('dashboard_index_supplier');
}
}
}
public function pageNotFoundAction()
{
return $this->render('@Twig/Exception/error.html.twig', [
'status_code' => 404,
'status_text' => 'Not Found!',
]);
}
}