src/Controller/HomeController.php line 930

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  8. use Knp\Component\Pager\PaginatorInterface;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  11. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  12. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  13. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  14. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use App\Entity\BFFestival;
  17. use App\Entity\BFEdition;
  18. use App\Entity\BFDistance;
  19. use App\Entity\BFUser;
  20. use App\Entity\BFResetPassword;
  21. use App\Entity\BFSubscription;
  22. use App\Entity\BFRouting;
  23. use App\Entity\BFInscription;
  24. use App\Entity\BFInscriptionUser;
  25. use App\Entity\BFChallenge;
  26. use App\Entity\BFChallengeEdition;
  27. use App\Object\AskMail;
  28. use App\Object\FestivalSearch;
  29. use App\Utilities\Mail;
  30. use App\Utilities\EditionUtilities;
  31. use App\Form\Type\BFUserDescriptionType;
  32. use App\Form\Type\AskMailType;
  33. use App\Form\Type\ContactType;
  34. use App\Form\Type\FestivalSearchType;
  35. use App\Form\Type\FestivalSearchWithDistanceType;
  36. use App\Form\Type\ModifyPasswordType;
  37. use App\Form\Type\ModifyEmailType;
  38. use App\Form\Type\AskPasswordType;
  39. use App\Form\Type\BFUserType;
  40. use App\Form\Type\SubscribeType;
  41. use App\Form\Type\UnsubscribeType;
  42. use App\Form\Type\BFInscriptionPairType;
  43. class HomeController extends AbstractController
  44. {
  45.     /**
  46.     * @Route("", name="home")
  47.     */
  48.     public function List(int $title=1)
  49.     {        
  50.         $editions $this->getDoctrine()->getRepository(BFEdition::class)->findNearestIsactive(true,9);
  51.         
  52.         return $this->render('home.html.twig', [
  53.             'bfeditions' => $editions,
  54.             'bfeditionid' => 1,
  55.         ]);
  56.     }
  57.     
  58.     /**
  59.     * @Route("/{routename}", name="home_route")
  60.     */
  61.     public function ShowRoute(string $routenameSessionInterface $sessionPaginatorInterface $paginatorUserPasswordEncoderInterface $passwordEncode,AuthenticationUtils $authenticationUtilsRequest $request)
  62.     {
  63.         //default routes
  64.         switch ($routename){
  65.             case 'signup':
  66.                 return $this->SignUp($request$passwordEncode);
  67.             case 'about':
  68.                 return $this->About();
  69.             case 'contact':
  70.                 return $this->Contact($request);
  71.             case 'search':
  72.                 return $this->searchResults($session$paginator$request);
  73.             case 'account':
  74.                 return $this->ShowAccount($request$passwordEncode);
  75.             case 'admin':
  76.                 return $this->ShowAccount($request$passwordEncode);
  77.             case 'login':
  78.                 return $this->login($authenticationUtils);
  79.             case 'all':
  80.                 return $this->all($request);
  81.             case 'allchallenges':
  82.                 return $this->allChallenges($session$paginator$request);
  83.             case 'subscriptions':
  84.                 return $this->ShowSubscriptions($session$paginator$request);
  85.             case 'termsofuse':
  86.                 return $this->termsOfUse($request);
  87.         }
  88.         
  89.         //festival or edition routes
  90.         $bfrouting $this->getDoctrine()->getRepository(BFRouting::class)->findOneBy([
  91.             'route' => $routename,
  92.         ]);
  93.         
  94.         if($bfrouting!=null)
  95.         {
  96.             if($bfrouting->getFestival()!=null)
  97.             {
  98.                 $festival=$bfrouting->getFestival();
  99.                 $isfestival=true;
  100.                 
  101.                 if($this->isGranted('option_uniqueurl_festival'$festival))
  102.                 {
  103.                     $edition $this->getDoctrine()->getRepository(BFEdition::class)->findOneBy([
  104.                         'festival' => $festival,
  105.                         'isactive' => true,
  106.                     ]);
  107.                     
  108.                     if($edition!=null)
  109.                         return $this->ViewEdition($edition->getId(),$request);
  110.                 }
  111.             }
  112.             else
  113.             {
  114.                 $edition=$bfrouting->getEdition();
  115.                 
  116.                 if($this->isGranted('option_uniqueurl_edition'$edition))
  117.                 {
  118.                     return $this->ViewEdition($edition->getId(), $request);
  119.                 }
  120.             }
  121.         }
  122.         
  123.         
  124.         
  125.         throw new NotFoundHttpException('This route does not exist');
  126.         
  127.     }
  128.     
  129.     public function termsOfUse(Request $resquest)
  130.     {
  131.         return $this->render('hometermsofuse.html.twig',[
  132.         ]);
  133.     }
  134.     
  135.     
  136.     public function searchResults(SessionInterface $sessionPaginatorInterface $paginatorRequest $request)
  137.     {
  138.         
  139.         $fsarray $request->request->get('festival_search');
  140.         $festivalsearch $session->get('search', new FestivalSearch());
  141.         
  142.         if($fsarray!=null)
  143.         {
  144.             $festivalsearch->hydrate($fsarray);
  145.             $session->set('search'$festivalsearch);
  146.         }
  147.         
  148.         $festivalsearch->CleanLocation();
  149.         
  150.         $formsearch $this->createForm(FestivalSearchWithDistanceType::class,$festivalsearch);
  151.         $formsearch->handleRequest($request);
  152.         if($formsearch->isSubmitted() && $formsearch->isValid())
  153.         {
  154.             $festivalsearch $formsearch->getData();
  155.             $session->set('search'$festivalsearch);
  156.             
  157.             return $this->redirect($request->getUri());
  158.         }
  159.                 
  160.         //get the possible editions
  161.         $bfeditionpossible $this->getDoctrine()->getRepository(BFEdition::class)->findAllPossible($festivalsearch); 
  162.         //compute the distances
  163.         if($festivalsearch->getPlaceid()!=null)
  164.         {
  165.             $bfdistancerepository $this->getDoctrine()->getRepository(BFDistance::class);
  166.             $newbfdistances EditionUtilities::ComputeDistance($bfeditionpossible,$festivalsearch,$bfdistancerepository);
  167.             //fetch the computed distances
  168.             $em$this->getDoctrine()->getManager();
  169.             foreach($newbfdistances as $bfdistance)
  170.             {
  171.                 $em->persist($bfdistance);
  172.             }
  173.             $em->flush();
  174.             
  175.             //filterbydistance
  176.             $filteredbfeditions EditionUtilities::FilterByDistance($bfeditionpossible$festivalsearch->getDistance());
  177.             
  178.             //set the filtered bfedition in the result search
  179.             $session->set('search_results'$filteredbfeditions);
  180.         }
  181.         else
  182.         {
  183.             $session->set('search_results'$bfeditionpossible);
  184.         }
  185.         
  186.         $pagination $paginator->paginate(
  187.                 $session->get('search_results'), /* query NOT result */
  188.                 $request->query->getInt('page'1), /*page number*/
  189.                 10 /*limit per page*/
  190.             );
  191.         
  192.         return $this->render('homesearch.html.twig', [
  193.             'formsearch' => $formsearch->createView(),
  194.             'pagination' => $pagination,
  195.             'haslocation' => $festivalsearch->getLocation()!=null,
  196.             'festivalsearchdistance' => $festivalsearch->getDistance()/1000,
  197.             'uuid' => uniqid(),
  198.          ]);
  199.     }
  200.     
  201.     
  202.     /**
  203.     * @Route("/edition/{id}", name="edition_view")
  204.     */
  205.     public function ViewEdition(int $idRequest $request)
  206.     {
  207.         $edition $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
  208.         $festival $edition->getFestival();
  209.         if($edition->getIsactive()==false)
  210.         {
  211.             $this->denyAccessUnlessGranted('edit'$festival); 
  212.             $this->addFlash('warning''L\'édition n\'est pas activée');
  213.         }
  214.         
  215.         //managesubscription
  216.         $user $this->getUser();
  217.         $hassubscribe false;
  218.         if($user!=null)
  219.         {
  220.             $subscription $this->getDoctrine()->getRepository(BFSubscription::class)->findOneBy([
  221.                 'user' => $user,
  222.                 'festival' => $festival,
  223.             ]);
  224.             if($subscription!=null)
  225.                 $hassubscribe=true;
  226.         }
  227.         if($hassubscribe)
  228.         {
  229.             $formsubscription $this->createForm(UnsubscribeType::class, null, [
  230.                 'attr' => ['class' => 'w-100'],
  231.             ]);
  232.         }
  233.         else
  234.         {
  235.             $formsubscription $this->createForm(SubscribeType::class, null, [
  236.                 'attr' => ['class' => 'w-100'],
  237.             ]);
  238.         }
  239.         $formsubscription->handleRequest($request);
  240.         if($formsubscription->isSubmitted() && $formsubscription->isValid())
  241.         {
  242.             $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  243.             
  244.             $em $this->getDoctrine()->getManager();
  245.             $action $formsubscription['subscription']->getData();
  246.             if($action=='subscribe')
  247.             {
  248.                 $bfsubscription = new BFSubscription();
  249.                 $bfsubscription->setUser($user);
  250.                 $bfsubscription->setFestival($festival);
  251.                 $bfsubscription->setSubscriptionsdate(new \DateTime('now'));
  252.                 
  253.                 $em->persist($bfsubscription);
  254.                 $em->flush();
  255.                 
  256.                 $this->addFlash('success''Votre abonnement a été pris en compte');
  257.             }
  258.             else if($action == 'unsubscribe' && isset($subscription))
  259.             {
  260.                 $em->remove($subscription);
  261.                 $em->flush();
  262.                 
  263.                 $this->addFlash('info''Votre abonnement a été supprimé');
  264.             }
  265.             
  266.             return $this->redirect($request->getUri());
  267.         }
  268.         
  269.         //manage ask mail form
  270.         $askmail=new AskMail();
  271.         $formaskmail $this->createForm(AskMailType::class, $askmail,[
  272.             'attr' => [
  273.                 'onsubmit' => 'return onaskmailsubmit(event) ;'
  274.             ]
  275.             ]);
  276.         
  277.         $formaskmail->handleRequest($request);
  278.         if ($formaskmail->isSubmitted() && $formaskmail->isValid()) {
  279.             $askmail $formaskmail->getData();
  280.             
  281.             $recaptchatoken $formaskmail['recaptchatoken']->getData();
  282.             
  283.             if(!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1''::1')))
  284.             {
  285.                 $recaptcha = new \ReCaptcha\ReCaptcha("6Le2aesUAAAAAPQQIKIv8gq0I5paSMTtJl6PRy-T");
  286.                 $resp $recaptcha->setExpectedAction('askmail')
  287.                     ->verify($recaptchatoken$_SERVER['REMOTE_ADDR']);
  288.                 //->setExpectedHostname('dev.bridgefestival.fr')
  289.                 if (!$resp->isSuccess()) {
  290.                     $this->addFlash('danger''Etes vous un robot?');
  291.                     return $this->redirect($request->getUri());
  292.                 }
  293.             }
  294.             //sendmail
  295.             $txtmessage "";
  296.             $subject "Demande d'informations";
  297.             $htmlmessage $this->renderView('mail/askinformation.html.twig', [
  298.                 'bfedition'=> $edition,
  299.                 'subject' => $subject,
  300.                 'askmail' => $askmail,
  301.             ]);
  302.             $admins $festival->getAdministrators()->getValues();
  303.             $owner $festival->getOwner();
  304.             
  305.             if($owner!=null)
  306.             {
  307.                 array_push($admins$owner);
  308.             }
  309.             if(count($admins)==0)
  310.             {
  311.                 $userrepository =$this->getDoctrine()->getRepository(BFUser::class);
  312.                 array_push($admins$userrepository->findByRole('ROLE_SUPER_ADMIN'));
  313.             }
  314.             $return Mail::SendMailToBFUsers($admins$askmail->getEmail(), $subject$htmlmessage$txtmessage);
  315.             
  316.             if($return ==true)
  317.             {
  318.                 $this->addFlash('success''Votre demande d\'informations a été envoyée');
  319.             }
  320.             else
  321.             {
  322.                 $this->addFlash('danger''Erreur lors de l\'envoi de la demande');
  323.             }
  324.             return $this->redirect($request->getUri());
  325.         }
  326.     
  327.         
  328.         return $this->render('homeeditiondetails.html.twig',[
  329.             'formsubscription' => $formsubscription->createView(),
  330.             'bfedition' => $edition,
  331.             'formaskmail' => $formaskmail->createView(),
  332.         ]);
  333.     }
  334.     /**
  335.     * @Route("/challenge/edition/{idedition}", name="challenge_view")
  336.     */
  337.     public function ShowChallenge(int $idedition,SessionInterface $sessionPaginatorInterface $paginatorRequest $request)
  338.     {
  339.         $bfchallengeedition $this->getDoctrine()->getRepository(BFChallengeEdition::class)->find($idedition);
  340.         $bfchallenge $bfchallengeedition->getChallenge();
  341.         //managesubscription
  342.         $user $this->getUser();
  343.         $hassubscribe false;
  344.         if($user!=null)
  345.         {
  346.             $subscription $this->getDoctrine()->getRepository(BFSubscription::class)->findOneBy([
  347.                 'user' => $user,
  348.                 'challenge' => $bfchallenge,
  349.             ]);
  350.             if($subscription!=null)
  351.                 $hassubscribe=true;
  352.         }
  353.         if($hassubscribe)
  354.         {
  355.             $formsubscription $this->createForm(UnsubscribeType::class, null, [
  356.                 'attr' => ['class' => 'w-100'],
  357.             ]);
  358.         }
  359.         else
  360.         {
  361.             $formsubscription $this->createForm(SubscribeType::class, null, [
  362.                 'attr' => ['class' => 'w-100'],
  363.             ]);
  364.         }
  365.         $formsubscription->handleRequest($request);
  366.         if($formsubscription->isSubmitted() && $formsubscription->isValid())
  367.         {
  368.             $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  369.             
  370.             $em $this->getDoctrine()->getManager();
  371.             $action $formsubscription['subscription']->getData();
  372.             if($action=='subscribe')
  373.             {
  374.                 $bfsubscription = new BFSubscription();
  375.                 $bfsubscription->setUser($user);
  376.                 $bfsubscription->setChallenge($bfchallenge);
  377.                 $bfsubscription->setSubscriptionsdate(new \DateTime('now'));
  378.                 
  379.                 $em->persist($bfsubscription);
  380.                 $em->flush();
  381.                 
  382.                 $this->addFlash('success''Votre abonnement a été pris en compte');
  383.             }
  384.             else if($action == 'unsubscribe' && isset($subscription))
  385.             {
  386.                 $em->remove($subscription);
  387.                 $em->flush();
  388.                 
  389.                 $this->addFlash('info''Votre abonnement a été supprimé');
  390.             }
  391.             
  392.             return $this->redirect($request->getUri());
  393.         }
  394.         
  395.         //get the possible editions
  396.         $bfeditions=$bfchallengeedition->getEditions();
  397.         
  398.         //put the list in the session for paginator
  399.         $session->set('show_challenge'$bfeditions);
  400.         
  401.         $pagination $paginator->paginate(
  402.                 $session->get('show_challenge'), /* query NOT result */
  403.                 $request->query->getInt('page'1), /*page number*/
  404.                 10 /*limit per page*/
  405.             );
  406.         
  407.         return $this->render('homechallenge.html.twig',[
  408.             'bfchallenge' => $bfchallenge,
  409.             'bfchallengeedition' => $bfchallengeedition,
  410.             'formsubscription' => $formsubscription->createView(),
  411.             'pagination' => $pagination,
  412.         ]);
  413.     }
  414.     
  415.     /**
  416.     * @Route("/account/subscriptions", name="account_subscription")
  417.     */
  418.     public function ShowAccountSubscriptions(Request $request)
  419.     {
  420.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  421.                 
  422.         $user $this->getUser();
  423.         
  424.         $subscriptions=$this->getDoctrine()->getRepository(BFSubscription::class)->findBy(['user'=>$user]);
  425.         
  426.         $festivalsubs= new ArrayCollection();
  427.         $challengesubs=new ArrayCollection();
  428.         
  429.         foreach($subscriptions as $subscription)
  430.         {
  431.             if($subscription->getFestival()!=null)
  432.             {
  433.                 $festivalsubs->add($subscription);
  434.             }
  435.             if($subscription->getChallenge()!=null)
  436.             {
  437.                 $challengesubs->add($subscription);
  438.             }
  439.         }
  440.                 
  441.          return $this->render('adminaccountsubscriptions.html.twig',[
  442.              'userdescription' => $user->getDescription(),
  443.             'bfsubscriptionsfestival' => $festivalsubs,
  444.              'bfsubscriptionschallenge' => $challengesubs,
  445.              'activeaccount' => 1,
  446.         ]);
  447.     }
  448.     
  449.     /**
  450.     * @Route("/account/inscriptions", name="account_inscriptions")
  451.     */
  452.     public function ShowAccountInscriptions(Request $request)
  453.     {
  454.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  455.         
  456.         $user $this->getUser();
  457.         
  458.         $userinscription $this->getDoctrine()->getRepository(BFInscriptionUser::class)->findOneBy([
  459.             'user'=>$user,
  460.         ]);
  461.         
  462.         $activeinscriptions = array();
  463.         $unactiveinscriptions = array();
  464.         
  465.         if($userinscription)
  466.         {
  467.             $tournoisinscriptions $userinscription->getAllInscriptions();
  468.             //Two lists: active and unactive inscriptions
  469.             
  470.             foreach($tournoisinscriptions as $tournoiinscription)
  471.             {
  472.                 if($tournoiinscription->getTournoi()->getEdition()->getIsactive()==true 
  473.                    && ($tournoiinscription->getTournoi()->getStartdate()>=date('Y-m-d') ||  $tournoiinscription->getTournoi()->getEnddate()<=date('Y-m-d'))
  474.                    )
  475.                 {
  476.                     array_push($activeinscriptions$tournoiinscription);            
  477.                 }
  478.                 else
  479.                 {
  480.                     array_push($unactiveinscriptions$tournoiinscription);
  481.                 }
  482.             }
  483.             //Sort the two list by startdate & enddate of the tournoi
  484.             uasort($activeinscriptions,array('App\Entity\BFInscription','sorting')); 
  485.             uasort($unactiveinscriptions,array('App\Entity\BFInscription','sorting')); 
  486.         }
  487.         $subscriptions=$this->getDoctrine()->getRepository(BFSubscription::class)->findBy(['user'=>$user]);
  488.         
  489.          return $this->render('adminaccountinscriptions.html.twig',[
  490.              'userdescription' => $user->getDescription(),
  491.             'bfinscriptionsactives' => $activeinscriptions,
  492.              'bfinscriptionsunactives' => $unactiveinscriptions,
  493.              'activeaccount' => 1,
  494.         ]);
  495.     }
  496.     
  497.     /**
  498.     * @Route("/account/inscription/{inscriptionid}", name="account_inscription_edit")
  499.     */
  500.     public function ShowAccountInscriptionEdit(int $inscriptionidRequest $request)
  501.     {
  502.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  503.         
  504.         $bfinscription $this->getDoctrine()->getRepository(BFInscription::class)->find($inscriptionid);
  505.         
  506.         $user $this->getUser();
  507.         
  508.         $canaccess false;
  509.         if($bfinscription!=null)
  510.         {
  511.             //Check if the user can modify it
  512.             $inscriptionsusers $bfinscription->getAllInscriptionUser();
  513.             
  514.             foreach($inscriptionsusers as $inscriptionuser)
  515.             {
  516.                 if($inscriptionuser->getUser()==$user)
  517.                 {
  518.                     $canaccess=true;
  519.                     break;
  520.                 }
  521.             }
  522.         }
  523.         
  524.         if($canaccess)
  525.         {
  526.             return $this->render('adminaccountinscriptionedit.html.twig',[
  527.             'tournoi' => $bfinscription->getTournoi(),
  528.             ]);
  529.         }
  530.         else
  531.         {
  532.             throw new AccessDeniedException();
  533.         }
  534.         
  535.     }
  536.     
  537.     /**
  538.     * @Route("/account/payments", name="account_payments")
  539.     */
  540.     public function ShowAccountPayments(Request $request)
  541.     {
  542.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  543.         
  544.         $user $this->getUser();
  545.         
  546.         $recentpayments=array();
  547.         $oldpayments=array();
  548.         $inwaitingpayments=array();
  549.         
  550.         //Separate the bfpaymentintentedition in 2 => recent and old
  551.         $bfpaymentintents $user->getBFPaymentIntentEditions();
  552.         
  553.         foreach($bfpaymentintents as $bfpaymentintent)
  554.         {
  555.             if($bfpaymentintent->getSuccessdate()!=null || $bfpaymentintent->getFailedtime()!=null)
  556.             {
  557.                 if($bfpaymentintent->getCreationdate()>new \DateTime('-6 months'))
  558.                 {
  559.                     array_push($recentpayments$bfpaymentintent);
  560.                 }
  561.                 else
  562.                 {
  563.                    array_push($oldpayments$bfpaymentintent); 
  564.                 }
  565.             }
  566.             else
  567.             {
  568.                 if($bfpaymentintent->getCreationdate()>new \DateTime('-1 hour'))
  569.                 {
  570.                     array_push($recentpayments$bfpaymentintent);
  571.                 }
  572.                 else if($bfpaymentintent->getCreationdate()>new \DateTime('-1 day'))
  573.                 {
  574.                     array_push($inwaitingpayments$bfpaymentintent);
  575.                 }
  576.             }
  577.         }
  578.         
  579.         return $this->render('adminaccountpayments.html.twig',[
  580.             'recentpayments' => $recentpayments,
  581.             'oldpayments' =>$oldpayments,
  582.             'inwaitingpayments' => $inwaitingpayments,
  583.             'userdescription' => $user->getDescription(),
  584.              'activeaccount' => 1,
  585.             ]);
  586.     }
  587.     
  588.     
  589.     public function ShowAccount(Request $requestUserPasswordEncoderInterface $passwordEncoder)
  590.     {
  591.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  592.                 
  593.         $user $this->getUser() ;
  594.         
  595.         $this->ClearUserResetPassword($user);
  596.         
  597.         //formdescription
  598.         $formuserdescription $this->createForm(BFUserDescriptionType::class, $user->getDescription());
  599.         
  600.         $formuserdescription->handleRequest($request);
  601.         if($formuserdescription->isSubmitted() && $formuserdescription->isValid()){
  602.             $description $formuserdescription->getData();
  603.             
  604.             $entityManager $this->getDoctrine()->getManager();
  605.             
  606.             //Update inscription if exist
  607.             $userinscription $this->getDoctrine()->getRepository(BFInscriptionUser::class)->findOneBy([
  608.                 'user'=>$user,
  609.             ]);
  610.             if($userinscription!=null)
  611.             {
  612.                 if($description->getName())
  613.                     $userinscription->setName($description->getName());
  614.                 if($description->getForname())
  615.                    $userinscription->setForname($description->getForname());
  616.                 if($description->getPhonenumber())
  617.                     $userinscription->setTelephonenumber($description->getPhonenumber());
  618.                 if($description->getLicencenumber())
  619.                     $userinscription->setLicencenumber(getLicencenumber());
  620.                 
  621.                 $entityManager->persist($userinscription);
  622.             }
  623.             
  624.             
  625.             $entityManager->persist($description);
  626.             $entityManager->flush();
  627.             
  628.             
  629.             
  630.             $this->addFlash('success''Les modifications sont enregistrées');
  631.             
  632.             return $this->redirect($request->getUri());
  633.         }
  634.         if($formuserdescription->isSubmitted() && !$formuserdescription->isValid())
  635.         {
  636.             foreach($formuserdescription->getErrors(true) as $error)
  637.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  638.             return $this->redirect($request->getUri());
  639.         }
  640.         
  641.         //formmodifypassword
  642.         $formuserpassword $this->createForm(ModifyPasswordType::class);
  643.         
  644.         $formuserpassword->handleRequest($request);
  645.         if($formuserpassword->isSubmitted() && $formuserpassword->isValid())
  646.         {
  647.             //Check actual password
  648.             $password $formuserpassword->getData()['actualpassword'];
  649.             //check password
  650.             $validpassword $passwordEncoder->isPasswordValid($user,$password);
  651.             
  652.             if($validpassword)
  653.             {
  654.                 $password $passwordEncoder->encodePassword($user$formuserpassword->getData()['plainPassword']);
  655.                 $user->setPassword($password);
  656.                 // 4) save the User!
  657.                 $entityManager $this->getDoctrine()->getManager();
  658.                 $entityManager->persist($user);
  659.                 $entityManager->flush();
  660.                 
  661.                 $this->addFlash('primary''Le mot de passe a été modifé');
  662.                 
  663.                 return $this->redirect($request->getUri());
  664.             }
  665.             else
  666.             {
  667.                 $formuserpassword->get('actualpassword')->addError(new FormError('Mauvais mot de passe'));
  668.             }
  669.         }
  670.         if($formuserpassword->isSubmitted() && !$formuserpassword->isValid())
  671.         {
  672.             foreach($formuserpassword->getErrors(true) as $error)
  673.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  674.             return $this->redirect($request->getUri());
  675.         }
  676.         
  677.         //formmodifyemail
  678.         $formuseremail $this->createForm(ModifyEmailType::class, null, ['email_placeholder' => $user->getEmail()]);
  679.         
  680.         $formuseremail->handleRequest($request);
  681.         if($formuseremail->isSubmitted() && $formuseremail->isValid())
  682.         {
  683.             //Check actual password
  684.             $password $formuseremail->getData()['password'];
  685.             //check password
  686.             $validpassword $passwordEncoder->isPasswordValid($user,$password);
  687.             
  688.             if($validpassword)
  689.             {
  690.                 $usermail $formuseremail->getData()['email'];
  691.                 $user->setEmail($usermail);
  692.                 
  693.                 $entityManager $this->getDoctrine()->getManager();
  694.                 $entityManager->persist($user);
  695.                 $entityManager->flush();
  696.                 
  697.                 $this->addFlash('primary''L\'adresse email a été modifée');
  698.                 
  699.                 return $this->redirect($request->getUri());
  700.             }
  701.             else
  702.             {
  703.                 $formuseremail->get('password')->addError(new FormError('Mauvais mot de passe'));
  704.             }
  705.         }
  706.         if($formuseremail->isSubmitted() && !$formuseremail->isValid())
  707.         {
  708.             foreach($formuseremail->getErrors(true) as $error)
  709.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  710.             return $this->redirect($request->getUri());
  711.         }
  712.         
  713.         //formdeleteuser
  714.         $formdeleteuser $this->createForm(AskPasswordType::class);
  715.         
  716.         $formdeleteuser->handleRequest($request);
  717.         if($formdeleteuser->isSubmitted() && $formdeleteuser->isValid())
  718.         {
  719.             $password $formdeleteuser->getData()['password'];
  720.             //check password
  721.             $validpassword $passwordEncoder->isPasswordValid($user,$password);
  722.             
  723.             if($validpassword)
  724.             {
  725.                 $this->get('security.token_storage')->setToken(null);
  726.                 $entityManager $this->getDoctrine()->getManager();
  727.                 $entityManager->remove($user);
  728.                 $entityManager->flush();
  729.                 
  730.                 $this->addFlash('primary''Le compte utilisateur a été supprimé');
  731.                 
  732.                 return $this->redirectToRoute('home');
  733.             }
  734.             
  735.         }
  736.         if($formdeleteuser->isSubmitted() && !$formdeleteuser->isValid())
  737.         {
  738.             foreach($formdeleteuser->getErrors(true) as $error)
  739.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  740.             return $this->redirect($request->getUri());
  741.         }
  742.         
  743.         return $this->render('adminaccount.html.twig', [
  744.             'userdescription' => $user->getDescription(),
  745.             'formuserdescription' => $formuserdescription->createView(),
  746.             'formuserpassword' => $formuserpassword->createView(),
  747.             'formuseremail' => $formuseremail->createView(),
  748.             'formuserdelete' => $formdeleteuser->createView(),
  749.             'activeaccount' => 1,
  750.         ]);
  751.     }
  752.     
  753.     public function SignUp(Request $requestUserPasswordEncoderInterface $passwordEncoder)
  754.     {
  755.         $user = new BFUser();
  756.         $form $this->createForm(BFUserType::class, $user,[
  757.             'attr' => [
  758.                 'onsubmit' => 'return onregistersubmit(event);'
  759.             ]
  760.         ]);
  761.         $form->handleRequest($request);
  762.         if ($form->isSubmitted() && $form->isValid()) {
  763.             $user $form->getData();
  764.             
  765.             $recaptchatoken $form['recaptchatoken']->getData();
  766.             
  767.             if(!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1''::1')))
  768.             {
  769.                 $recaptcha = new \ReCaptcha\ReCaptcha("6Le2aesUAAAAAPQQIKIv8gq0I5paSMTtJl6PRy-T");
  770.                 $resp $recaptcha->setExpectedAction('register')
  771.                     ->verify($recaptchatoken$_SERVER['REMOTE_ADDR']);
  772.                 //->setExpectedHostname('dev.bridgefestival.fr')
  773.                 if (!$resp->isSuccess()) {
  774.                     $this->addFlash('danger''Etes vous un robot?');
  775.                     return $this->redirect($request->getUri());
  776.                 }
  777.             }
  778.             
  779.             $password $passwordEncoder->encodePassword($user$user->getPlainPassword());
  780.             $user->setPassword($password);
  781.             $entityManager $this->getDoctrine()->getManager();
  782.             $entityManager->persist($user);
  783.             $entityManager->flush();
  784.             
  785.             //Get the inscriptionsuser qui ont cette adresse mail
  786.             $inscriptionusers $this->getDoctrine()->getRepository(BFInscriptionUser::class)->findAllWithoutUserByMail($user->getEmail());
  787.                         
  788.             if(count($inscriptionusers)>0)
  789.             {
  790.                 $first $inscriptionusers[0]->Copy();
  791.                 $first->setUser($user);
  792.                 $entityManager->persist($first);
  793.                 
  794.                 //now we replace all by the new one
  795.                 foreach($inscriptionusers as $inscriptionuser)
  796.                 {
  797.                     $inscriptions $inscriptionuser->getAllInscriptions();
  798.                     
  799.                     foreach($inscriptions as $inscription)
  800.                     {
  801.                         if($inscription->ReplaceInscriptionUser($inscriptionuser$first))
  802.                         {
  803.                             $entityManager->persist($inscription);
  804.                         }
  805.                         else
  806.                         {
  807.                             $this->addFlash('warning''Erreur pour récupérer l\inscription au festival '.$inscription->getTournoi()->getEdition()->getFestival()->getName());
  808.                         }
  809.                     }
  810.                 }
  811.                 
  812.                 $entityManager->flush();
  813.             }
  814.             $token = new UsernamePasswordToken($usernull'main'$user->getRoles());
  815.             $this->container->get('security.token_storage')->setToken($token);
  816.             $this->container->get('session')->set('_security_main'serialize($token));
  817.             
  818.             $this->addFlash('primary''Bienvenue, votre compte a été créé');
  819.             
  820.             return $this->redirectToRoute('home_route',[
  821.                 'routename' => 'account',
  822.             ]);
  823.         }
  824.         if($form->isSubmitted() && !$form->isValid())
  825.         {
  826.             foreach($form->getErrors(true) as $error)
  827.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  828.             return $this->redirect($request->getUri());
  829.         }
  830.                 
  831.         return $this->render('homesignup.html.twig', [
  832.             'formregister' => $form->createView(),
  833.         ]);
  834.     }
  835.     
  836.     public function About()
  837.     {
  838.         return $this->render('homeabout.html.twig', [
  839.             
  840.         ]);
  841.     }
  842.     
  843.     public function Contact(Request $request)
  844.     {
  845.         //form contact
  846.         $formcontact $this->createForm(ContactType::class,null,[
  847.             'attr' => [
  848.                 'onsubmit' => 'return oncontactsubmit(event);'
  849.             ]
  850.         ]);
  851.         $formcontact->handleRequest($request);
  852.         if($formcontact->isSubmitted() && $formcontact->isValid()){
  853.             $name $formcontact->getData()['name'];
  854.             $email $formcontact->getData()['email'];
  855.             $message $formcontact->getData()['message'];
  856.             
  857.             $recaptchatoken $formcontact['recaptchatoken']->getData();
  858.             
  859.             if(!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1''::1')))
  860.             {
  861.                 $recaptcha = new \ReCaptcha\ReCaptcha("6Le2aesUAAAAAPQQIKIv8gq0I5paSMTtJl6PRy-T");
  862.                 $resp $recaptcha->setExpectedAction('contact')
  863.                     ->verify($recaptchatoken$_SERVER['REMOTE_ADDR']);
  864.                 //->setExpectedHostname('dev.bridgefestival.fr')
  865.                 if (!$resp->isSuccess()) {
  866.                     $this->addFlash('danger''Etes vous un robot?');
  867.                     return $this->redirect($request->getUri());
  868.                 }
  869.             }
  870.             
  871.             $txtmessage "Demande de ".$name." dont l'adresse mail est ".$email." et le message est: ".$message;
  872.             $subject "Contact";
  873.             $htmlmessage $this->renderView('mail/contactmail.html.twig', [
  874.                 'subject' => $subject,
  875.                 'name' => $name,
  876.                 'email' => $email,
  877.                 'message' => $message,
  878.             ]);
  879.             $return Mail::SendMailToAdmin($email$subject$htmlmessage$txtmessage);
  880.             if($return ==false)
  881.             {
  882.                 $this->addFlash('danger''Erreur lors de l\'envoi du mail');
  883.             }
  884.             else
  885.             {
  886.                 $this->addFlash('success''Le message a été envoyé');
  887.             }
  888.             
  889.             return $this->redirect($request->getUri());
  890.         }
  891.         if($formcontact->isSubmitted() && !$formcontact->isValid())
  892.         {
  893.             foreach($formcontact->getErrors(true) as $error)
  894.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  895.             return $this->redirect($request->getUri());
  896.         }
  897.         
  898.                 
  899.         return $this->render('homecontact.html.twig', [
  900.             'formcontact' => $formcontact->createView(),
  901.         ]);
  902.     }
  903.     
  904.     public function ShowSubscriptions(SessionInterface $sessionPaginatorInterface $paginatorRequest $request)
  905.     {
  906.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  907.         
  908.         $user$this->getUser();
  909.         
  910.         $editions=array();
  911.         
  912.         if($user!=null)
  913.         {
  914.             $editions $this->getDoctrine()->getRepository(BFEdition::class)->findAllSubscriptions($usertrue);
  915.         }
  916.         $session->set('homefavorites'$editions);
  917.         
  918.         $pagination $paginator->paginate(
  919.                 $session->get('homefavorites'), /* query NOT result */
  920.                 $request->query->getInt('page'1), /*page number*/
  921.                 10 /*limit per page*/
  922.             );
  923.         
  924.         return $this->render('homesubscriptions.html.twig', [
  925.             'pagination' => $pagination,
  926.          ]);
  927.     }
  928.     
  929.     public function all(Request $request)
  930.     {
  931.         $festivals $this->getDoctrine()
  932.             ->getRepository(BFFestival::class)
  933.             ->findAllOrderByName();
  934.         
  935.         
  936.         return $this->render('homeall.html.twig', [
  937.             'bffestivals' => $festivals,
  938.         ]);
  939.     }
  940.     
  941.     public function AllChallenges(SessionInterface $sessionPaginatorInterface $paginatorRequest $request)
  942.     {
  943.         $challenges $this->getDoctrine()
  944.             ->getRepository(BFChallenge::class)
  945.             ->findAllOrderByName();
  946.         
  947.         $session->set('allchallenges'$challenges);
  948.         
  949.         $pagination $paginator->paginate(
  950.                 $session->get('allchallenges'), /* query NOT result */
  951.                 $request->query->getInt('page'1), /*page number*/
  952.                 10 /*limit per page*/
  953.             );
  954.         
  955.         return $this->render('homeallchallenges.html.twig', [
  956.             'pagination' => $pagination,
  957.         ]);
  958.     }
  959.     
  960.         
  961.     private function ClearUserResetPassword(BFUser $bfuser)
  962.     {
  963.         //get bfreset from user id
  964.         $bfresetpassword $this->getDoctrine()->getRepository(BFResetPassword::class)->findOneBy(['user'=>$bfuser]);
  965.         
  966.         if($bfresetpassword!=null)
  967.         {
  968.             $entityManager $this->getDoctrine()->getManager();
  969.             $entityManager->remove($bfresetpassword);
  970.             $entityManager->flush();
  971.         }
  972.         
  973.     }
  974. }
  975. ?>