src/Controller/HomeController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use App\Repository\UserPlatformRepository;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use App\Acme\Bundle\Utility\ViewUtility\UtilityMenusBackend;
  10. use App\Acme\Bundle\Utility\TemplatesUtility\MenusStandard;
  11. use App\Form\SubscriptionForm\UserMultilType;
  12. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  13. use App\Entity\UserPlatform;
  14. use App\Entity\Product;
  15. use Exception;
  16. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  17. class HomeController extends AbstractController
  18. {
  19.     /**
  20.      * @Route("/", name="app_home")
  21.      */
  22.     public function index(EntityManagerInterface $entityManager, AuthorizationCheckerInterface $authorizationChecker): Response
  23.     {
  24.         
  25.         return $this->redirectToRoute('app_product_index', [], Response::HTTP_SEE_OTHER);
  26.         
  27.         $templatesMenus = new UtilityMenusBackend(0);
  28.         MenusStandard::setTitleTemplate($templatesMenus);
  29.         MenusStandard::setTitleApplication($templatesMenus);
  30.         MenusStandard::setMenusStandard($templatesMenus, $authorizationChecker);
  31.         
  32.         return $this->render('home/index.html.twig', [
  33.             'templatesMenus'=>$templatesMenus,
  34.         ]);
  35.     }
  36.     /**
  37.      * @Route("/inscription-client", name="app_home_inscription", methods={"GET", "POST"})
  38.      */
  39.     public function inscription(Request $request,UserPlatformRepository $userPlatformRepository,UserPasswordEncoderInterface $passwordEncoder): Response
  40.     {
  41.         $user = new UserPlatform();
  42.         $form = $this->createForm(UserMultilType::class, $user);
  43.         $form->handleRequest($request);
  44.         $arrayresult = array("error"=>false,"msg"=>"");
  45.         if ($form->isSubmitted() && $form->isValid()) {
  46.             try{
  47.                 if($user->getPassword() != $form->get('confirmpass')->getData()){
  48.                         $arrayresult['error'] = true;
  49.                         $arrayresult['msg'] = "Mot de passe non confirmé.";
  50.                     } else if(strpos($user->getEmail()," ")){
  51.                         $arrayresult['error'] = true;
  52.                         $arrayresult['msg'] = "l'identifiant \"".$user->getEmail()."\" ne doit pas contenir un espace.";
  53.                     }
  54.                     else if(strlen($user->getEmail()) < 5){
  55.                         $arrayresult['error'] = true;
  56.                         $arrayresult['msg'] = "l'identifiant \"".$user->getEmail()."\" doit contenir plus de 5 caracteres.";
  57.                     }
  58.                     else {
  59.                         $user->setRoles(["ROLE_CUSTOMER"]);
  60.                         $user->setPassword(
  61.                         $passwordEncoder->encodePassword($user, $user->getPassword()));
  62.                         $userPlatformRepository->add($user, true);
  63.                         return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
  64.                     }
  65.             }
  66.             catch(Exception $exc){
  67.                 return $this->render('frontView/error.html.twig', [
  68.                         'msg' => $exc->getMessage(),
  69.                 ]);
  70.             }
  71.         }
  72.         return $this->renderForm('frontView/inscription/inscription.html.twig', [
  73.             'form' => $form,
  74.             'arrayresult' => $arrayresult,
  75.         ]);
  76.     }
  77.     /**
  78.      * @Route("/aroma-madagascar", name="app_aroma_madagascar", methods={"GET", "POST"})
  79.      */
  80.     public function aromaMadagascar(EntityManagerInterface $entityManager): Response
  81.     {
  82.         $orderby = array('points'=>'DESC');
  83.         $criteria = array();
  84.         return $this->render('frontView/boutique/indexaroma.html.twig', [
  85.             'products' => $entityManager->getRepository(Product::class)->getProductShop(3)
  86.         ]);
  87.     }
  88.     /**
  89.      * @Route("/kiki-creation-madagascar", name="app_kiki_madagascar", methods={"GET", "POST"})
  90.      */
  91.     public function kikiMadagascar(EntityManagerInterface $entityManager): Response
  92.     {
  93.         $orderby = array('points'=>'DESC');
  94.         $criteria = array();
  95.         return $this->render('frontView/boutique/indexkiki.html.twig', [
  96.             'products' => $entityManager->getRepository(Product::class)->getProductShop(4)
  97.         ]);
  98.     }
  99.     /**
  100.      * @Route("/aroma-madagascar", name="app_aroma_madagascar", methods={"GET", "POST"})
  101.      */
  102.     /**
  103.      * @Route("/infos", name="app_rapeto_infos", methods={"GET", "POST"})
  104.      */
  105.     public function infosRapeto(): Response
  106.     {
  107.         return $this->render('frontView/boutique/infos.html.twig', [
  108.         ]);
  109.     }
  110.     /**
  111.      * @Route("/access-denied", name="app_home_access_denied")
  112.      */
  113.     public function accesDenied(EntityManagerInterface $entityManager): Response
  114.     {
  115.         return $this->render('security/error403.html.twig', [
  116.         ]);
  117.     }
  118. }