src/Controller/DefaultController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class DefaultController extends AbstractController
  10. {
  11.     private $doctrine;
  12.     public function __construct(ManagerRegistry $doctrine)
  13.     {
  14.         $this->doctrine $doctrine;
  15.     }
  16.     /**
  17.      * @Route("/", name="homepage")
  18.      */
  19.     public function indexAction(Request $requestTranslatorInterface $translator)
  20.     {
  21.         $user $this->getUser();
  22.         if(!$user)
  23.         {
  24.           return $this->render('security/login.html.twig', [
  25.             'last_username' => null,
  26.             'error' => null,
  27.           ]);
  28.         } elseif ($user->getUserStatus()->getId() != 2) {
  29.             $this->get('security.token_storage')->setToken(null);
  30.             $this->get('session')->invalidate();
  31.             return $this->render('security/login.html.twig', [
  32.                 'last_username' => null,
  33.                 'error' => null,
  34.             ]);
  35.         }
  36.         else {
  37.           // replace this example code with whatever you need
  38.           if($user->getRole()->getId() == User::ROLE_ADMIN || $user->getRole()->getId() == User::ROLE_SUPER_ADMIN)
  39.           {
  40.               return $this->redirectToRoute('dashboard_index');
  41.            /* return $this->render('dashboard/index.html.twig', [
  42.                 'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
  43.             ]);*/
  44.           } elseif ($user->getRole()->getId() == User::ROLE_CUSTOMER) {
  45.               if ($user->getCustomer() === null)
  46.               {
  47.                   if (count($user->getUserCustomerList()) >= 1)
  48.                   {
  49.                       $user->setCustomer($user->getUserCustomerList()->getValues()[0]->getCustomer());
  50.                       $em $this->doctrine->getManager();
  51.                       $em->flush();
  52.                   } else {
  53.                       $this->get('security.token_storage')->setToken(null);
  54.                       $this->get('session')->invalidate();
  55.                       $no_customer_supplier $translator->trans('error.no_customer_supplier');
  56.                       return $this->render('@Twig/Exception/error.html.twig', [
  57.                           'status_code' => 500,
  58.                           'status_text' => $no_customer_supplier,
  59.                       ]);
  60.                   }
  61.               }
  62.             return $this->redirectToRoute('dashboard_index_customer');
  63.           } else {
  64.               return $this->redirectToRoute('dashboard_index_supplier');
  65.             }
  66.         }
  67.     }
  68.     public function pageNotFoundAction()
  69.     {
  70.         return $this->render('@Twig/Exception/error.html.twig', [
  71.             'status_code' => 404,
  72.             'status_text' => 'Not Found!',
  73.         ]);
  74.     }
  75. }