src/Controller/DefaultController.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the Pimcore X Installation by
  4.  * ercas GmbH & CO. KG <https://www.ercasdieagentur.de>
  5.  *
  6.  *  @license GPLv3
  7.  */
  8. namespace App\Controller;
  9. use App\mvk\Model\DataObject\AbstractUser;
  10. use Pimcore\Controller\FrontendController;
  11. use Pimcore\Model\Document;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. use Symfony\Component\HttpFoundation\Request;
  14. class DefaultController extends FrontendController
  15. {
  16.     public function damageAction(Request $request)
  17.     {
  18.         return $this->render('layout/damage-declaration.html.twig', []);
  19.     }
  20.     public function defaultAction(Request $request)
  21.     {
  22.         $user$this->getUser();
  23.         $documentId=$this->document->getId();
  24.         if ($this->checkUrlRegex($request->getPathInfo()) && $user && $user instanceof AbstractUser && !$user->getTwoFactorAuth() && !$user->getSkipTwoFactorAuth()  && $user->getActive() && $documentId!=$this->getWebSettingValue('2FA_infoPageDocument') && $documentId!=$this->getWebSettingValue('2FA_vmVerification') && $documentId!=$this->getWebSettingValue('2FA_activationDocument')) {
  25.             $targetDocumentId $user->getTwoFactorRequested() ? $this->getWebSettingValue('2FA_infoPageDocument') : $this->getWebSettingValue('2FA_activationRequiredDocument');
  26.             $targetDocument Document::getById($targetDocumentId);
  27.             return new RedirectResponse($targetDocument->getFullPath());
  28.         }
  29.         $access$this->checkPagePermissions();
  30.         if (!$access) {
  31.             $accessDeniedDocument $this->getAccessDeniedDocument();
  32.             $baseUrl '';
  33.             return new RedirectResponse($baseUrl.$accessDeniedDocument->getFullPath());
  34.         }
  35.         return $this->render('html/02_body/02_main/main.html.twig', []);
  36.     }
  37.     public function angularAction(Request $request)
  38.     {
  39.         $access$this->checkPagePermissions();
  40.         if (!$access) {
  41.             $accessDeniedDocument $this->getAccessDeniedDocument();
  42.             $baseUrl '';
  43.             return new RedirectResponse($baseUrl.$accessDeniedDocument->getFullPath());
  44.         }
  45.         return $this->render('html/02_body/angular.html.twig', []);
  46.     }
  47.     public function mailAction(Request $request)
  48.     {
  49.         return $this->render('mail/mail.html.twig', []);
  50.     }
  51.     public function mailActionCustom(Request $request)
  52.     {
  53.         return $this->render('mail/custom-mail.html.twig', ['params'=>null]);
  54.     }
  55.     private function checkPagePermissions()
  56.     {
  57.         $permission$this->document->getProperty('pagePermissions');
  58.         if ($permission && !$this->editmode) {
  59.             return  $this->isGranted($permission);
  60.         }
  61.         return true;
  62.     }
  63.     private function checkUrlRegex($url)
  64.     {
  65.         $patterns 'admin|authentication|zwei-faktor|2fa_activation|2fa_qrcode_generate|2fa_code_verify';
  66.         $regex '/' $patterns'/';
  67.         if (preg_match($regex$url)) {
  68.             return false ;
  69.         } else {
  70.             return true;
  71.         }
  72.     }
  73.     private function getWebSettingValue($name)
  74.     {
  75.         $document \Pimcore\Model\WebsiteSetting::getByName($namenullnull);
  76.         $document $document $document->getData() : null ;
  77.         return $document $document->getId() : null;
  78.     }
  79.     private function getAccessDeniedDocument()
  80.     {
  81.         if ($this->document->hasProperty('accessDeniedPage')) {
  82.             $accessDeniedDocId=$this->document->getProperty('accessDeniedPage')->getId();
  83.         } else {
  84.             $accessDeniedDocId=1;
  85.         }
  86.         return  Document::getById($accessDeniedDocId);
  87.     }
  88. }