src/Controller/DefaultController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Model\DataObject\User;
  4. use Pimcore\Controller\FrontendController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Security\Core\Security as FrontSecurity;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Pimcore\Model\WebsiteSetting;
  11. use Pimcore\Model\Document\PageSnippet;
  12. use Pimcore\Tool;
  13. use Symfony\Component\HttpFoundation\RequestStack;
  14. class DefaultController extends FrontendController
  15. {
  16.     /**
  17.      * @Template
  18.      * @param Request $request
  19.      * @return array
  20.      */
  21.     public function checkLanguageAction(Request $requestFrontSecurity $security)
  22.     {
  23.         $validLanguages Tool::getValidLanguages();
  24.         $acceptLang $validLanguages;
  25.         $defaultLang Tool::getDefaultLanguage();
  26.         if(!$this->editmode){
  27.             if(isset($_COOKIE["ptjlang"]) && $_COOKIE["ptjlang"]!=""){
  28.                 $lang $_COOKIE["ptjlang"];
  29.                 $lang in_array($lang$acceptLang) ? $lang $defaultLang;
  30.             }else{
  31.                 $lang substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 02);
  32.                 $lang in_array($lang$acceptLang) ? $lang $defaultLang;
  33.                 $cookieDuration time() + intval(WebsiteSetting::getByName('cookieLangDuration')->getData());
  34.                 setcookie("ptjlang",$lang,$cookieDuration,"/");
  35.             }
  36.             return $this->redirect("/".$lang,301);
  37.         }
  38.     }
  39.     /**
  40.      * @Template
  41.      * @param Request $request
  42.      * @return array
  43.      */
  44.     public function homeAction(Request $requestFrontSecurity $security)
  45.     {
  46.         if(!$this->editmode):
  47.             $securityUser $security->getUser();
  48.             if($securityUser){
  49.                 $user User::getByUsername($securityUser->getUserIdentifier())->load()[0];
  50.                 if($user->getStatus() == "unverified"){
  51.                     if($user->getRenewToken()){
  52.                         return $this->redirectToRoute("verify_email_itsme", ["renew_token" => $user->getRenewToken()]);
  53.                     }else{
  54.                         return $this->redirectToRoute("beforeLogout");
  55.                     }
  56.                 }
  57.             }
  58.         endif;
  59.         return $this->render('default/home.html.twig',[
  60.         ]);
  61.     }
  62.     /**
  63.      * @Template
  64.      * @param Request $request
  65.      * @route("/{_locale}/suspended", name="suspendedRoute",methods={"GET"})
  66.      * @return array
  67.      */
  68.     public function suspendedAction(Request $requestFrontSecurity $security)
  69.     {
  70.         return $this->render('default/suspended.html.twig',[
  71.         ]);
  72.     }
  73.     /**
  74.      * @Template
  75.      * @param Request $request
  76.      * @return array
  77.      */
  78.     public function defaultAction(Request $request)
  79.     {
  80.         return [];
  81.     }
  82.     /**
  83.      * @Template
  84.      * @param Request $request
  85.      * @return array
  86.      */
  87.     public function footerAction(Request $request) {
  88.         return [];
  89.     }
  90.     /**
  91.      * @Template
  92.      * @param RequestStack $requestStack
  93.      * @return array
  94.      */
  95.     public function customMenuAction(RequestStack $requestStack) {
  96.         $request $requestStack->getMainRequest();
  97.         
  98.         return ['mainRequest' => $request];
  99.     }
  100. }