<?php
namespace App\Controller;
use App\Model\DataObject\User;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security as FrontSecurity;
use Symfony\Contracts\Translation\TranslatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Pimcore\Model\WebsiteSetting;
use Pimcore\Model\Document\PageSnippet;
use Pimcore\Tool;
use Symfony\Component\HttpFoundation\RequestStack;
class DefaultController extends FrontendController
{
/**
* @Template
* @param Request $request
* @return array
*/
public function checkLanguageAction(Request $request, FrontSecurity $security)
{
$validLanguages = Tool::getValidLanguages();
$acceptLang = $validLanguages;
$defaultLang = Tool::getDefaultLanguage();
if(!$this->editmode){
if(isset($_COOKIE["ptjlang"]) && $_COOKIE["ptjlang"]!=""){
$lang = $_COOKIE["ptjlang"];
$lang = in_array($lang, $acceptLang) ? $lang : $defaultLang;
}else{
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$lang = in_array($lang, $acceptLang) ? $lang : $defaultLang;
$cookieDuration = time() + intval(WebsiteSetting::getByName('cookieLangDuration')->getData());
setcookie("ptjlang",$lang,$cookieDuration,"/");
}
return $this->redirect("/".$lang,301);
}
}
/**
* @Template
* @param Request $request
* @return array
*/
public function homeAction(Request $request, FrontSecurity $security)
{
if(!$this->editmode):
$securityUser = $security->getUser();
if($securityUser){
$user = User::getByUsername($securityUser->getUserIdentifier())->load()[0];
if($user->getStatus() == "unverified"){
if($user->getRenewToken()){
return $this->redirectToRoute("verify_email_itsme", ["renew_token" => $user->getRenewToken()]);
}else{
return $this->redirectToRoute("beforeLogout");
}
}
}
endif;
return $this->render('default/home.html.twig',[
]);
}
/**
* @Template
* @param Request $request
* @route("/{_locale}/suspended", name="suspendedRoute",methods={"GET"})
* @return array
*/
public function suspendedAction(Request $request, FrontSecurity $security)
{
return $this->render('default/suspended.html.twig',[
]);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function defaultAction(Request $request)
{
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function footerAction(Request $request) {
return [];
}
/**
* @Template
* @param RequestStack $requestStack
* @return array
*/
public function customMenuAction(RequestStack $requestStack) {
$request = $requestStack->getMainRequest();
return ['mainRequest' => $request];
}
}