src/Controller/Front/AppController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Profile;
  4. use App\Entity\User;
  5. use App\Security\JsonAuthenticator;
  6. use App\Service\SerializeService;
  7. use App\Service\Tools;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
  14. /**
  15.  * Class AppController
  16.  * @package App\Controller\Front
  17.  * @Route(path="", name="app_")
  18.  */
  19. class AppController extends AbstractController
  20. {
  21.     private SerializeService $serializeService;
  22.     private EntityManagerInterface $em;
  23.     public function __construct(
  24.         SerializeService $serializeService,
  25.         EntityManagerInterface $em
  26.     ) {
  27.         $this->serializeService $serializeService;
  28.         $this->em $em;
  29.     }
  30.     /**
  31.      * @return Response
  32.      * @Route("/{vueRouting}", name="index", requirements={"vueRouting"="^(?!api|js|ipocam|mail|institution|workspace/menubuilder|matrix/menubuilder|login/to|mobile|pdfmenu|_(profiler|wdt)).*"}, defaults={"vueRouting"=null})
  33.      */
  34.     public function index(Request $request)
  35.     {
  36.         /** @var User $user */
  37.         $user $this->getUser();
  38.         if (!is_null($user)) {
  39.             if ($user->getProfile()->getRole() !== Profile::ROLE_CUSTOMER) {
  40.                 return $this->redirectToRoute('admin_login');
  41.             }
  42.             $user $this->serializeService->serializeUser($user);
  43.         }
  44.         $urlNotIndxeds = [
  45.             '/mobile',
  46.             '/pdfmenu',
  47.         ];
  48.         $isIndexed true;
  49.         foreach ($urlNotIndxeds as $urlNotIndxed) {
  50.             if (str_contains($request->getUri(), $urlNotIndxed)) {
  51.                 $isIndexed false;
  52.             }
  53.         }
  54.         return $this->render('front/app/mizogoo.html.twig', [
  55.             'isAuthenticated' => base64_encode(json_encode(!empty($user))),
  56.             'user' => base64_encode(json_encode($user)),
  57.             'isIndexed' => $isIndexed,
  58.         ]);
  59.     }
  60.     /**
  61.      * @param $hash
  62.      * @param JsonAuthenticator $authenticator
  63.      * @param GuardAuthenticatorHandler $guardHandler
  64.      * @param Request $request
  65.      * @return Response
  66.      * @Route("/login/to/{hash}", name="login_to")
  67.      */
  68.     public function loginTo($hashJsonAuthenticator $authenticatorGuardAuthenticatorHandler $guardHandlerRequest $request): Response
  69.     {
  70.         /** @var User $userTo */
  71.         $userTo $this->em->getRepository(User::class)->find(Tools::decrypt($hash));
  72.         if ($userTo) {
  73.             if ($userTo->getProfile()->getRole() == Profile::ROLE_CUSTOMER) {
  74.                 if (str_contains($request->headers->get('referer'), $this->generateUrl('admin_customer_view', ['customer' => $userTo->getId()])) ||
  75.                     str_contains($request->headers->get('referer'), $this->generateUrl('admin_index'))) {
  76.                     $guardHandler->authenticateUserAndHandleSuccess(
  77.                         $userTo,
  78.                         $request,
  79.                         $authenticator,
  80.                         'user_prodiver'
  81.                     );
  82.                     return $this->redirectToRoute('app_index');
  83.                 }
  84.             }
  85.         }
  86.         return $this->redirectToRoute('admin_index');
  87.     }
  88. }