<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use App\Repository\UserPlatformRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use App\Acme\Bundle\Utility\ViewUtility\UtilityMenusBackend;
use App\Acme\Bundle\Utility\TemplatesUtility\MenusStandard;
use App\Form\SubscriptionForm\UserMultilType;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use App\Entity\UserPlatform;
use App\Entity\Product;
use Exception;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class HomeController extends AbstractController
{
/**
* @Route("/", name="app_home")
*/
public function index(EntityManagerInterface $entityManager, AuthorizationCheckerInterface $authorizationChecker): Response
{
return $this->redirectToRoute('app_product_index', [], Response::HTTP_SEE_OTHER);
$templatesMenus = new UtilityMenusBackend(0);
MenusStandard::setTitleTemplate($templatesMenus);
MenusStandard::setTitleApplication($templatesMenus);
MenusStandard::setMenusStandard($templatesMenus, $authorizationChecker);
return $this->render('home/index.html.twig', [
'templatesMenus'=>$templatesMenus,
]);
}
/**
* @Route("/inscription-client", name="app_home_inscription", methods={"GET", "POST"})
*/
public function inscription(Request $request,UserPlatformRepository $userPlatformRepository,UserPasswordEncoderInterface $passwordEncoder): Response
{
$user = new UserPlatform();
$form = $this->createForm(UserMultilType::class, $user);
$form->handleRequest($request);
$arrayresult = array("error"=>false,"msg"=>"");
if ($form->isSubmitted() && $form->isValid()) {
try{
if($user->getPassword() != $form->get('confirmpass')->getData()){
$arrayresult['error'] = true;
$arrayresult['msg'] = "Mot de passe non confirmé.";
} else if(strpos($user->getEmail()," ")){
$arrayresult['error'] = true;
$arrayresult['msg'] = "l'identifiant \"".$user->getEmail()."\" ne doit pas contenir un espace.";
}
else if(strlen($user->getEmail()) < 5){
$arrayresult['error'] = true;
$arrayresult['msg'] = "l'identifiant \"".$user->getEmail()."\" doit contenir plus de 5 caracteres.";
}
else {
$user->setRoles(["ROLE_CUSTOMER"]);
$user->setPassword(
$passwordEncoder->encodePassword($user, $user->getPassword()));
$userPlatformRepository->add($user, true);
return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
}
}
catch(Exception $exc){
return $this->render('frontView/error.html.twig', [
'msg' => $exc->getMessage(),
]);
}
}
return $this->renderForm('frontView/inscription/inscription.html.twig', [
'form' => $form,
'arrayresult' => $arrayresult,
]);
}
/**
* @Route("/aroma-madagascar", name="app_aroma_madagascar", methods={"GET", "POST"})
*/
public function aromaMadagascar(EntityManagerInterface $entityManager): Response
{
$orderby = array('points'=>'DESC');
$criteria = array();
return $this->render('frontView/boutique/indexaroma.html.twig', [
'products' => $entityManager->getRepository(Product::class)->getProductShop(3)
]);
}
/**
* @Route("/kiki-creation-madagascar", name="app_kiki_madagascar", methods={"GET", "POST"})
*/
public function kikiMadagascar(EntityManagerInterface $entityManager): Response
{
$orderby = array('points'=>'DESC');
$criteria = array();
return $this->render('frontView/boutique/indexkiki.html.twig', [
'products' => $entityManager->getRepository(Product::class)->getProductShop(4)
]);
}
/**
* @Route("/aroma-madagascar", name="app_aroma_madagascar", methods={"GET", "POST"})
*/
/**
* @Route("/infos", name="app_rapeto_infos", methods={"GET", "POST"})
*/
public function infosRapeto(): Response
{
return $this->render('frontView/boutique/infos.html.twig', [
]);
}
/**
* @Route("/access-denied", name="app_home_access_denied")
*/
public function accesDenied(EntityManagerInterface $entityManager): Response
{
return $this->render('security/error403.html.twig', [
]);
}
}