<?php
namespace App\Controller;
use Twig\Environment;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Finder\Finder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use App\Repository\UserRepository;
use App\Service\UserService;
use Vanilla\JsConnect\JsConnect;
final class PageGeneratorController extends AbstractController
{
/** @var Environment */
private $twig;
/** @var ChannelContextInterface */
private $channelContext;
private Jsconnect $jsconnect;
public function __construct(Environment $twig, Jsconnect $jsconnect)
{
$this->twig = $twig;
$this->jsconnect = $jsconnect;
}
public function menuAction(): Response
{
return $this->render('@SyliusShop/Menu/_pageMenu.html.twig');
}
/**
* @Route("/old_version", name="old_version")
*/
public function oldversionAction(Request $request): Response
{
$finderwindows64 = new Finder();
$windowsfiles64 = $finderwindows64->files()->name('*.zip')->in($this->get('kernel')->getProjectDir() . "/public/versions/old/Windows/x64");
$finderwindows32 = new Finder();
$windowsfiles32 = $finderwindows32->files()->name('*.zip')->in($this->get('kernel')->getProjectDir() . "/public/versions/old/Windows/x86");
$findermac = new Finder();
$macfiles = $findermac->files()->name('*.zip')->in($this->get('kernel')->getProjectDir() . "/public/versions/old/OSX");
return $this->render('page_generator/oldversion.html.twig', array('windowsfiles64' => $windowsfiles64,'windowsfiles32' => $windowsfiles32, 'macfiles' => $macfiles));
}
/**
* @Route("/download", name="download")
public function downloadAction(Request $request): Response
{
return $this->render('page_generator/download.html.twig');
}
*/
/**
* @Route("/formation", name="formation")
*/
public function formationAction(Request $request): Response
{
return $this->render('page_generator/formation.html.twig');
}
/**
* @Route("/forum", name="forum")
*/
public function forumAction(Request $request, UserService $userService): Response
{
$user = $this->getUser();
// Récupérer les paramètres JSConnect
$clientID = $this->getParameter('JSclientIDv2');
$secret = $this->getParameter('JSsecretv2');
$signedIn = false;
if ($user === null || !$user->isVerified()) {
// Retourner une chaîne vide si l'utilisateur n'est pas connecté ou non vérifié
return $this->render('page_generator/embedforum.html.twig', ['myssostring' => '']);
}
$this->jsconnect->setSigningCredentials($clientID, $secret);
// Vérifier si l'utilisateur est vérifié
$signedIn = true;
// Récupérer les informations du client
$customer = $userService->getCustomerByUser($user);
$payload = json_encode([
'client_id' => $clientID,
'uniqueid' => $user->getId(),
'name' => $customer->getPseudo(),
'email' => $customer->getEmail(),
'client_id' => $clientID,
'timestamp' => time(),
]);
// Renseigner les informations utilisateur
$this->jsconnect->setUniqueID($user->getId())
->setName($customer->getPseudo())
->setEmail($customer->getEmail());
$signature = hash_hmac('sha1', $payload, $secret);
// Générer le SSO string
$ssoString = base64_encode($payload) . ' ' . $signature;
// Générer la chaîne SSO pour Vanilla Forums
//$ssoString = $this->jsconnect->ssoString($userdata, $clientID, $secret);
// Rendre le template avec la chaîne SSO
return $this->render('page_generator/embedforum.html.twig', [
'myssostring' => $ssoString,
]);
}
/**
* @Route("/wiki", name="wiki")
*/
public function wikiAction(Request $request): Response
{
return $this->render('page_generator/wiki.html.twig');
}
/**
* @Route("/redirectlogin", name="redirectlogin")
*/
public function redirectloginAction(Request $request): Response
{
$context = new RequestContext();
$context->fromRequest(Request::createFromGlobals());
$url = $this->generateUrl('sylius_shop_login', [
'_locale' => 'fr',
], UrlGeneratorInterface::ABSOLUTE_URL);
$js = '<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script><script type="text/javascript">jQuery(document).ready( function() {
top.location = "' . $url . '";});</script>';
$response = new Response();
$response->prepare($request);
$response->setContent($js);
$response->send();
//return $this->redirect($url);
//return $this->redirectToRoute('sylius_shop_login', [], 301);
}
/**
* @Route("/redirectlogout", name="redirectlogout")
*/
public function redirectlogoutAction(Request $request): Response
{
$context = new RequestContext();
$context->fromRequest(Request::createFromGlobals());
$url = $this->generateUrl('sylius_shop_logout', ['_locale' => 'fr',], UrlGeneratorInterface::ABSOLUTE_URL);
$js = '<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script><script type="text/javascript">jQuery(document).ready( function() {
top.location = "' . $url . '";});</script>';
$response = new Response();
$response->prepare($request);
$response->setContent($js);
$response->send();
}
/**
* @Route("/redirectregister", name="redirectregister")
*/
public function redirectregisterAction(Request $request): Response
{
$context = new RequestContext();
$context->fromRequest(Request::createFromGlobals());
$url = $this->generateUrl('sylius_shop_register', ['_locale' => 'fr',], UrlGeneratorInterface::ABSOLUTE_URL);
$js = '<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script><script type="text/javascript">jQuery(document).ready( function() { top.location = "' . $url . '";});</script>';
$response = new Response();
$response->prepare($request);
$response->setContent($js);
$response->send();
// return $this->redirect($url);
//return $this->redirectToRoute('sylius_shop_register', [], 301);
}
/**
* @Route("/electronique", name="electronique")
*/
public function electroniqueAction(Request $request): Response
{
$code = array('Board_Taxons','DMX_HF','PWM_DIMMER_Taxon', 'HF_PROJECTOR__Taxon','books');
return $this->render('page_generator/electronique.html.twig', array('code' => $code, 'maxresult' => -1));
}
/**
* @Route("/features", name="features")
*/
public function featuresAction(Request $request): Response
{
return $this->render('page_generator/features.html.twig');
}
/**
* @Route("/liens", name="liens")
*/
public function liensAction(Request $request): Response
{
return $this->render('page_generator/liens.html.twig');
}
/**
* @Route("/about", name="about")
*/
public function aboutAction(Request $request): Response
{
return $this->render('page_generator/about.html.twig');
}
/**
* @Route("/shipping", name="shipping")
*/
public function deliveryAction(Request $request): Response
{
return $this->render('page_generator/shipping.html.twig');
}
/**
* @Route("/FAQ", name="FAQ")
*/
public function FAQAction(Request $request): Response
{
return $this->render('page_generator/FAQ.html.twig');
}
/**
* @Route("/privacy", name="privacy")
*/
public function privacyAction(Request $request): Response
{
return $this->render('page_generator/privacy.html.twig');
}
/**
* @Route("/return", name="return")
*/
public function returnAction(Request $request): Response
{
return $this->render('page_generator/return.html.twig');
}
/**
* @Route("/terms", name="terms")
*/
public function termsAction(Request $request): Response
{
return $this->render('page_generator/terms.html.twig');
}
/**
* @Route("/confirmationresend", name="confirmationresend")
*/
public function resendVerificationTokenfromMailAction(Request $request): Response
{
if ($request->getMethod() == Request::METHOD_POST)
{
$email = $request->request->get('emailverif');
if (null !== $email)
{
$customer = $this->container->get('sylius.repository.customer')->findOneBy(['email' => $email ]);
$user = $customer->getUser();
if (null === $user) {
$this->addTranslatedFlash('error', 'sylius.user.verify_no_user');
return $this->redirectToRoute('sylius_shop_login');
}
else if (null !== $user->getVerifiedAt()) {
$errorMessage = $this->getSyliusAttribute(
$request,
'error_flash',
'sylius.user.verify_verified_email'
);
$this->addTranslatedFlash('error', 'sylius.user.verify_verified_email');
return $this->redirectToRoute('sylius_shop_login');
}
}
else
{
$this->addTranslatedFlash('error', 'Please give a valide email');
return $this->redirectToRoute('sylius_shop_login');
}
}
$sender = $this->container->get('sylius.email_sender');
$logpath = 'https://www.hephaestos.eu/build/img/baniere1024x768.png';
$localeCode = $this->get('sylius.context.locale')->getLocaleCode();
$channel = $this->container->get('sylius.context.channel')->getChannel();
$sender->send(\Sylius\Bundle\UserBundle\Mailer\Emails::EMAIL_VERIFICATION_TOKEN, [$email], ['user' => $user, 'channel' => $channel, 'localeCode' => $localeCode, 'image_src' => $logpath]);
// $sender->send(\Sylius\Bundle\UserBundle\Mailer\Emails::EMAIL_VERIFICATION_TOKEN, [$email], ['user' => $user, 'image_src' => $logpath]);
/** @var GeneratorInterface $tokenGenerator */
/* $tokenGenerator = $this->container->get(sprintf('sylius.%s.token_generator.email_verification', $user->getUsername()));
$user->setEmailVerificationToken($tokenGenerator->generate());
$this->manager->flush();*/
/* $eventDispatcher = $this->container->get('event_dispatcher');
$eventDispatcher->dispatch(UserEvents::REQUEST_VERIFICATION_TOKEN, new GenericEvent($user));*/
$this->addTranslatedFlash('success', 'sylius.user.verify_email_request');
return $this->redirectToRoute('sylius_shop_login');
}
/**
* {@inheritdoc}
*/
protected function addTranslatedFlash(string $type, string $message): void
{
$translator = $this->container->get('translator');
$this->container->get('session')->getFlashBag()->add($type, @$this->translator->trans($message, [], 'flashes'));
}
}