<?php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\BFFestival;
use App\Entity\BFEdition;
use App\Entity\BFDistance;
use App\Entity\BFUser;
use App\Entity\BFResetPassword;
use App\Entity\BFSubscription;
use App\Entity\BFRouting;
use App\Entity\BFInscription;
use App\Entity\BFInscriptionUser;
use App\Entity\BFChallenge;
use App\Entity\BFChallengeEdition;
use App\Object\AskMail;
use App\Object\FestivalSearch;
use App\Utilities\Mail;
use App\Utilities\EditionUtilities;
use App\Form\Type\BFUserDescriptionType;
use App\Form\Type\AskMailType;
use App\Form\Type\ContactType;
use App\Form\Type\FestivalSearchType;
use App\Form\Type\FestivalSearchWithDistanceType;
use App\Form\Type\ModifyPasswordType;
use App\Form\Type\ModifyEmailType;
use App\Form\Type\AskPasswordType;
use App\Form\Type\BFUserType;
use App\Form\Type\SubscribeType;
use App\Form\Type\UnsubscribeType;
use App\Form\Type\BFInscriptionPairType;
class HomeController extends AbstractController
{
/**
* @Route("", name="home")
*/
public function List(int $title=1)
{
$editions = $this->getDoctrine()->getRepository(BFEdition::class)->findNearestIsactive(true,9);
return $this->render('home.html.twig', [
'bfeditions' => $editions,
'bfeditionid' => 1,
]);
}
/**
* @Route("/{routename}", name="home_route")
*/
public function ShowRoute(string $routename, SessionInterface $session, PaginatorInterface $paginator, UserPasswordEncoderInterface $passwordEncode,AuthenticationUtils $authenticationUtils, Request $request)
{
//default routes
switch ($routename){
case 'signup':
return $this->SignUp($request, $passwordEncode);
case 'about':
return $this->About();
case 'contact':
return $this->Contact($request);
case 'search':
return $this->searchResults($session, $paginator, $request);
case 'account':
return $this->ShowAccount($request, $passwordEncode);
case 'admin':
return $this->ShowAccount($request, $passwordEncode);
case 'login':
return $this->login($authenticationUtils);
case 'all':
return $this->all($request);
case 'allchallenges':
return $this->allChallenges($session, $paginator, $request);
case 'subscriptions':
return $this->ShowSubscriptions($session, $paginator, $request);
case 'termsofuse':
return $this->termsOfUse($request);
}
//festival or edition routes
$bfrouting = $this->getDoctrine()->getRepository(BFRouting::class)->findOneBy([
'route' => $routename,
]);
if($bfrouting!=null)
{
if($bfrouting->getFestival()!=null)
{
$festival=$bfrouting->getFestival();
$isfestival=true;
if($this->isGranted('option_uniqueurl_festival', $festival))
{
$edition = $this->getDoctrine()->getRepository(BFEdition::class)->findOneBy([
'festival' => $festival,
'isactive' => true,
]);
if($edition!=null)
return $this->ViewEdition($edition->getId(),$request);
}
}
else
{
$edition=$bfrouting->getEdition();
if($this->isGranted('option_uniqueurl_edition', $edition))
{
return $this->ViewEdition($edition->getId(), $request);
}
}
}
throw new NotFoundHttpException('This route does not exist');
}
public function termsOfUse(Request $resquest)
{
return $this->render('hometermsofuse.html.twig',[
]);
}
public function searchResults(SessionInterface $session, PaginatorInterface $paginator, Request $request)
{
$fsarray = $request->request->get('festival_search');
$festivalsearch = $session->get('search', new FestivalSearch());
if($fsarray!=null)
{
$festivalsearch->hydrate($fsarray);
$session->set('search', $festivalsearch);
}
$festivalsearch->CleanLocation();
$formsearch = $this->createForm(FestivalSearchWithDistanceType::class,$festivalsearch);
$formsearch->handleRequest($request);
if($formsearch->isSubmitted() && $formsearch->isValid())
{
$festivalsearch = $formsearch->getData();
$session->set('search', $festivalsearch);
return $this->redirect($request->getUri());
}
//get the possible editions
$bfeditionpossible = $this->getDoctrine()->getRepository(BFEdition::class)->findAllPossible($festivalsearch);
//compute the distances
if($festivalsearch->getPlaceid()!=null)
{
$bfdistancerepository = $this->getDoctrine()->getRepository(BFDistance::class);
$newbfdistances = EditionUtilities::ComputeDistance($bfeditionpossible,$festivalsearch,$bfdistancerepository);
//fetch the computed distances
$em= $this->getDoctrine()->getManager();
foreach($newbfdistances as $bfdistance)
{
$em->persist($bfdistance);
}
$em->flush();
//filterbydistance
$filteredbfeditions = EditionUtilities::FilterByDistance($bfeditionpossible, $festivalsearch->getDistance());
//set the filtered bfedition in the result search
$session->set('search_results', $filteredbfeditions);
}
else
{
$session->set('search_results', $bfeditionpossible);
}
$pagination = $paginator->paginate(
$session->get('search_results'), /* query NOT result */
$request->query->getInt('page', 1), /*page number*/
10 /*limit per page*/
);
return $this->render('homesearch.html.twig', [
'formsearch' => $formsearch->createView(),
'pagination' => $pagination,
'haslocation' => $festivalsearch->getLocation()!=null,
'festivalsearchdistance' => $festivalsearch->getDistance()/1000,
'uuid' => uniqid(),
]);
}
/**
* @Route("/edition/{id}", name="edition_view")
*/
public function ViewEdition(int $id, Request $request)
{
$edition = $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
$festival = $edition->getFestival();
if($edition->getIsactive()==false)
{
$this->denyAccessUnlessGranted('edit', $festival);
$this->addFlash('warning', 'L\'édition n\'est pas activée');
}
//managesubscription
$user = $this->getUser();
$hassubscribe = false;
if($user!=null)
{
$subscription = $this->getDoctrine()->getRepository(BFSubscription::class)->findOneBy([
'user' => $user,
'festival' => $festival,
]);
if($subscription!=null)
$hassubscribe=true;
}
if($hassubscribe)
{
$formsubscription = $this->createForm(UnsubscribeType::class, null, [
'attr' => ['class' => 'w-100'],
]);
}
else
{
$formsubscription = $this->createForm(SubscribeType::class, null, [
'attr' => ['class' => 'w-100'],
]);
}
$formsubscription->handleRequest($request);
if($formsubscription->isSubmitted() && $formsubscription->isValid())
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$em = $this->getDoctrine()->getManager();
$action = $formsubscription['subscription']->getData();
if($action=='subscribe')
{
$bfsubscription = new BFSubscription();
$bfsubscription->setUser($user);
$bfsubscription->setFestival($festival);
$bfsubscription->setSubscriptionsdate(new \DateTime('now'));
$em->persist($bfsubscription);
$em->flush();
$this->addFlash('success', 'Votre abonnement a été pris en compte');
}
else if($action == 'unsubscribe' && isset($subscription))
{
$em->remove($subscription);
$em->flush();
$this->addFlash('info', 'Votre abonnement a été supprimé');
}
return $this->redirect($request->getUri());
}
//manage ask mail form
$askmail=new AskMail();
$formaskmail = $this->createForm(AskMailType::class, $askmail,[
'attr' => [
'onsubmit' => 'return onaskmailsubmit(event) ;'
]
]);
$formaskmail->handleRequest($request);
if ($formaskmail->isSubmitted() && $formaskmail->isValid()) {
$askmail = $formaskmail->getData();
$recaptchatoken = $formaskmail['recaptchatoken']->getData();
if(!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
$recaptcha = new \ReCaptcha\ReCaptcha("6Le2aesUAAAAAPQQIKIv8gq0I5paSMTtJl6PRy-T");
$resp = $recaptcha->setExpectedAction('askmail')
->verify($recaptchatoken, $_SERVER['REMOTE_ADDR']);
//->setExpectedHostname('dev.bridgefestival.fr')
if (!$resp->isSuccess()) {
$this->addFlash('danger', 'Etes vous un robot?');
return $this->redirect($request->getUri());
}
}
//sendmail
$txtmessage = "";
$subject = "Demande d'informations";
$htmlmessage = $this->renderView('mail/askinformation.html.twig', [
'bfedition'=> $edition,
'subject' => $subject,
'askmail' => $askmail,
]);
$admins = $festival->getAdministrators()->getValues();
$owner = $festival->getOwner();
if($owner!=null)
{
array_push($admins, $owner);
}
if(count($admins)==0)
{
$userrepository =$this->getDoctrine()->getRepository(BFUser::class);
array_push($admins, $userrepository->findByRole('ROLE_SUPER_ADMIN'));
}
$return = Mail::SendMailToBFUsers($admins, $askmail->getEmail(), $subject, $htmlmessage, $txtmessage);
if($return ==true)
{
$this->addFlash('success', 'Votre demande d\'informations a été envoyée');
}
else
{
$this->addFlash('danger', 'Erreur lors de l\'envoi de la demande');
}
return $this->redirect($request->getUri());
}
return $this->render('homeeditiondetails.html.twig',[
'formsubscription' => $formsubscription->createView(),
'bfedition' => $edition,
'formaskmail' => $formaskmail->createView(),
]);
}
/**
* @Route("/challenge/edition/{idedition}", name="challenge_view")
*/
public function ShowChallenge(int $idedition,SessionInterface $session, PaginatorInterface $paginator, Request $request)
{
$bfchallengeedition = $this->getDoctrine()->getRepository(BFChallengeEdition::class)->find($idedition);
$bfchallenge = $bfchallengeedition->getChallenge();
//managesubscription
$user = $this->getUser();
$hassubscribe = false;
if($user!=null)
{
$subscription = $this->getDoctrine()->getRepository(BFSubscription::class)->findOneBy([
'user' => $user,
'challenge' => $bfchallenge,
]);
if($subscription!=null)
$hassubscribe=true;
}
if($hassubscribe)
{
$formsubscription = $this->createForm(UnsubscribeType::class, null, [
'attr' => ['class' => 'w-100'],
]);
}
else
{
$formsubscription = $this->createForm(SubscribeType::class, null, [
'attr' => ['class' => 'w-100'],
]);
}
$formsubscription->handleRequest($request);
if($formsubscription->isSubmitted() && $formsubscription->isValid())
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$em = $this->getDoctrine()->getManager();
$action = $formsubscription['subscription']->getData();
if($action=='subscribe')
{
$bfsubscription = new BFSubscription();
$bfsubscription->setUser($user);
$bfsubscription->setChallenge($bfchallenge);
$bfsubscription->setSubscriptionsdate(new \DateTime('now'));
$em->persist($bfsubscription);
$em->flush();
$this->addFlash('success', 'Votre abonnement a été pris en compte');
}
else if($action == 'unsubscribe' && isset($subscription))
{
$em->remove($subscription);
$em->flush();
$this->addFlash('info', 'Votre abonnement a été supprimé');
}
return $this->redirect($request->getUri());
}
//get the possible editions
$bfeditions=$bfchallengeedition->getEditions();
//put the list in the session for paginator
$session->set('show_challenge', $bfeditions);
$pagination = $paginator->paginate(
$session->get('show_challenge'), /* query NOT result */
$request->query->getInt('page', 1), /*page number*/
10 /*limit per page*/
);
return $this->render('homechallenge.html.twig',[
'bfchallenge' => $bfchallenge,
'bfchallengeedition' => $bfchallengeedition,
'formsubscription' => $formsubscription->createView(),
'pagination' => $pagination,
]);
}
/**
* @Route("/account/subscriptions", name="account_subscription")
*/
public function ShowAccountSubscriptions(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->getUser();
$subscriptions=$this->getDoctrine()->getRepository(BFSubscription::class)->findBy(['user'=>$user]);
$festivalsubs= new ArrayCollection();
$challengesubs=new ArrayCollection();
foreach($subscriptions as $subscription)
{
if($subscription->getFestival()!=null)
{
$festivalsubs->add($subscription);
}
if($subscription->getChallenge()!=null)
{
$challengesubs->add($subscription);
}
}
return $this->render('adminaccountsubscriptions.html.twig',[
'userdescription' => $user->getDescription(),
'bfsubscriptionsfestival' => $festivalsubs,
'bfsubscriptionschallenge' => $challengesubs,
'activeaccount' => 1,
]);
}
/**
* @Route("/account/inscriptions", name="account_inscriptions")
*/
public function ShowAccountInscriptions(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->getUser();
$userinscription = $this->getDoctrine()->getRepository(BFInscriptionUser::class)->findOneBy([
'user'=>$user,
]);
$activeinscriptions = array();
$unactiveinscriptions = array();
if($userinscription)
{
$tournoisinscriptions = $userinscription->getAllInscriptions();
//Two lists: active and unactive inscriptions
foreach($tournoisinscriptions as $tournoiinscription)
{
if($tournoiinscription->getTournoi()->getEdition()->getIsactive()==true
&& ($tournoiinscription->getTournoi()->getStartdate()>=date('Y-m-d') || $tournoiinscription->getTournoi()->getEnddate()<=date('Y-m-d'))
)
{
array_push($activeinscriptions, $tournoiinscription);
}
else
{
array_push($unactiveinscriptions, $tournoiinscription);
}
}
//Sort the two list by startdate & enddate of the tournoi
uasort($activeinscriptions,array('App\Entity\BFInscription','sorting'));
uasort($unactiveinscriptions,array('App\Entity\BFInscription','sorting'));
}
$subscriptions=$this->getDoctrine()->getRepository(BFSubscription::class)->findBy(['user'=>$user]);
return $this->render('adminaccountinscriptions.html.twig',[
'userdescription' => $user->getDescription(),
'bfinscriptionsactives' => $activeinscriptions,
'bfinscriptionsunactives' => $unactiveinscriptions,
'activeaccount' => 1,
]);
}
/**
* @Route("/account/inscription/{inscriptionid}", name="account_inscription_edit")
*/
public function ShowAccountInscriptionEdit(int $inscriptionid, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$bfinscription = $this->getDoctrine()->getRepository(BFInscription::class)->find($inscriptionid);
$user = $this->getUser();
$canaccess = false;
if($bfinscription!=null)
{
//Check if the user can modify it
$inscriptionsusers = $bfinscription->getAllInscriptionUser();
foreach($inscriptionsusers as $inscriptionuser)
{
if($inscriptionuser->getUser()==$user)
{
$canaccess=true;
break;
}
}
}
if($canaccess)
{
return $this->render('adminaccountinscriptionedit.html.twig',[
'tournoi' => $bfinscription->getTournoi(),
]);
}
else
{
throw new AccessDeniedException();
}
}
/**
* @Route("/account/payments", name="account_payments")
*/
public function ShowAccountPayments(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->getUser();
$recentpayments=array();
$oldpayments=array();
$inwaitingpayments=array();
//Separate the bfpaymentintentedition in 2 => recent and old
$bfpaymentintents = $user->getBFPaymentIntentEditions();
foreach($bfpaymentintents as $bfpaymentintent)
{
if($bfpaymentintent->getSuccessdate()!=null || $bfpaymentintent->getFailedtime()!=null)
{
if($bfpaymentintent->getCreationdate()>new \DateTime('-6 months'))
{
array_push($recentpayments, $bfpaymentintent);
}
else
{
array_push($oldpayments, $bfpaymentintent);
}
}
else
{
if($bfpaymentintent->getCreationdate()>new \DateTime('-1 hour'))
{
array_push($recentpayments, $bfpaymentintent);
}
else if($bfpaymentintent->getCreationdate()>new \DateTime('-1 day'))
{
array_push($inwaitingpayments, $bfpaymentintent);
}
}
}
return $this->render('adminaccountpayments.html.twig',[
'recentpayments' => $recentpayments,
'oldpayments' =>$oldpayments,
'inwaitingpayments' => $inwaitingpayments,
'userdescription' => $user->getDescription(),
'activeaccount' => 1,
]);
}
public function ShowAccount(Request $request, UserPasswordEncoderInterface $passwordEncoder)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->getUser() ;
$this->ClearUserResetPassword($user);
//formdescription
$formuserdescription = $this->createForm(BFUserDescriptionType::class, $user->getDescription());
$formuserdescription->handleRequest($request);
if($formuserdescription->isSubmitted() && $formuserdescription->isValid()){
$description = $formuserdescription->getData();
$entityManager = $this->getDoctrine()->getManager();
//Update inscription if exist
$userinscription = $this->getDoctrine()->getRepository(BFInscriptionUser::class)->findOneBy([
'user'=>$user,
]);
if($userinscription!=null)
{
if($description->getName())
$userinscription->setName($description->getName());
if($description->getForname())
$userinscription->setForname($description->getForname());
if($description->getPhonenumber())
$userinscription->setTelephonenumber($description->getPhonenumber());
if($description->getLicencenumber())
$userinscription->setLicencenumber(getLicencenumber());
$entityManager->persist($userinscription);
}
$entityManager->persist($description);
$entityManager->flush();
$this->addFlash('success', 'Les modifications sont enregistrées');
return $this->redirect($request->getUri());
}
if($formuserdescription->isSubmitted() && !$formuserdescription->isValid())
{
foreach($formuserdescription->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formmodifypassword
$formuserpassword = $this->createForm(ModifyPasswordType::class);
$formuserpassword->handleRequest($request);
if($formuserpassword->isSubmitted() && $formuserpassword->isValid())
{
//Check actual password
$password = $formuserpassword->getData()['actualpassword'];
//check password
$validpassword = $passwordEncoder->isPasswordValid($user,$password);
if($validpassword)
{
$password = $passwordEncoder->encodePassword($user, $formuserpassword->getData()['plainPassword']);
$user->setPassword($password);
// 4) save the User!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
$entityManager->flush();
$this->addFlash('primary', 'Le mot de passe a été modifé');
return $this->redirect($request->getUri());
}
else
{
$formuserpassword->get('actualpassword')->addError(new FormError('Mauvais mot de passe'));
}
}
if($formuserpassword->isSubmitted() && !$formuserpassword->isValid())
{
foreach($formuserpassword->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formmodifyemail
$formuseremail = $this->createForm(ModifyEmailType::class, null, ['email_placeholder' => $user->getEmail()]);
$formuseremail->handleRequest($request);
if($formuseremail->isSubmitted() && $formuseremail->isValid())
{
//Check actual password
$password = $formuseremail->getData()['password'];
//check password
$validpassword = $passwordEncoder->isPasswordValid($user,$password);
if($validpassword)
{
$usermail = $formuseremail->getData()['email'];
$user->setEmail($usermail);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
$entityManager->flush();
$this->addFlash('primary', 'L\'adresse email a été modifée');
return $this->redirect($request->getUri());
}
else
{
$formuseremail->get('password')->addError(new FormError('Mauvais mot de passe'));
}
}
if($formuseremail->isSubmitted() && !$formuseremail->isValid())
{
foreach($formuseremail->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formdeleteuser
$formdeleteuser = $this->createForm(AskPasswordType::class);
$formdeleteuser->handleRequest($request);
if($formdeleteuser->isSubmitted() && $formdeleteuser->isValid())
{
$password = $formdeleteuser->getData()['password'];
//check password
$validpassword = $passwordEncoder->isPasswordValid($user,$password);
if($validpassword)
{
$this->get('security.token_storage')->setToken(null);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($user);
$entityManager->flush();
$this->addFlash('primary', 'Le compte utilisateur a été supprimé');
return $this->redirectToRoute('home');
}
}
if($formdeleteuser->isSubmitted() && !$formdeleteuser->isValid())
{
foreach($formdeleteuser->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
return $this->render('adminaccount.html.twig', [
'userdescription' => $user->getDescription(),
'formuserdescription' => $formuserdescription->createView(),
'formuserpassword' => $formuserpassword->createView(),
'formuseremail' => $formuseremail->createView(),
'formuserdelete' => $formdeleteuser->createView(),
'activeaccount' => 1,
]);
}
public function SignUp(Request $request, UserPasswordEncoderInterface $passwordEncoder)
{
$user = new BFUser();
$form = $this->createForm(BFUserType::class, $user,[
'attr' => [
'onsubmit' => 'return onregistersubmit(event);'
]
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user = $form->getData();
$recaptchatoken = $form['recaptchatoken']->getData();
if(!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
$recaptcha = new \ReCaptcha\ReCaptcha("6Le2aesUAAAAAPQQIKIv8gq0I5paSMTtJl6PRy-T");
$resp = $recaptcha->setExpectedAction('register')
->verify($recaptchatoken, $_SERVER['REMOTE_ADDR']);
//->setExpectedHostname('dev.bridgefestival.fr')
if (!$resp->isSuccess()) {
$this->addFlash('danger', 'Etes vous un robot?');
return $this->redirect($request->getUri());
}
}
$password = $passwordEncoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($password);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
$entityManager->flush();
//Get the inscriptionsuser qui ont cette adresse mail
$inscriptionusers = $this->getDoctrine()->getRepository(BFInscriptionUser::class)->findAllWithoutUserByMail($user->getEmail());
if(count($inscriptionusers)>0)
{
$first = $inscriptionusers[0]->Copy();
$first->setUser($user);
$entityManager->persist($first);
//now we replace all by the new one
foreach($inscriptionusers as $inscriptionuser)
{
$inscriptions = $inscriptionuser->getAllInscriptions();
foreach($inscriptions as $inscription)
{
if($inscription->ReplaceInscriptionUser($inscriptionuser, $first))
{
$entityManager->persist($inscription);
}
else
{
$this->addFlash('warning', 'Erreur pour récupérer l\inscription au festival '.$inscription->getTournoi()->getEdition()->getFestival()->getName());
}
}
}
$entityManager->flush();
}
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->container->get('security.token_storage')->setToken($token);
$this->container->get('session')->set('_security_main', serialize($token));
$this->addFlash('primary', 'Bienvenue, votre compte a été créé');
return $this->redirectToRoute('home_route',[
'routename' => 'account',
]);
}
if($form->isSubmitted() && !$form->isValid())
{
foreach($form->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
return $this->render('homesignup.html.twig', [
'formregister' => $form->createView(),
]);
}
public function About()
{
return $this->render('homeabout.html.twig', [
]);
}
public function Contact(Request $request)
{
//form contact
$formcontact = $this->createForm(ContactType::class,null,[
'attr' => [
'onsubmit' => 'return oncontactsubmit(event);'
]
]);
$formcontact->handleRequest($request);
if($formcontact->isSubmitted() && $formcontact->isValid()){
$name = $formcontact->getData()['name'];
$email = $formcontact->getData()['email'];
$message = $formcontact->getData()['message'];
$recaptchatoken = $formcontact['recaptchatoken']->getData();
if(!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
$recaptcha = new \ReCaptcha\ReCaptcha("6Le2aesUAAAAAPQQIKIv8gq0I5paSMTtJl6PRy-T");
$resp = $recaptcha->setExpectedAction('contact')
->verify($recaptchatoken, $_SERVER['REMOTE_ADDR']);
//->setExpectedHostname('dev.bridgefestival.fr')
if (!$resp->isSuccess()) {
$this->addFlash('danger', 'Etes vous un robot?');
return $this->redirect($request->getUri());
}
}
$txtmessage = "Demande de ".$name." dont l'adresse mail est ".$email." et le message est: ".$message;
$subject = "Contact";
$htmlmessage = $this->renderView('mail/contactmail.html.twig', [
'subject' => $subject,
'name' => $name,
'email' => $email,
'message' => $message,
]);
$return = Mail::SendMailToAdmin($email, $subject, $htmlmessage, $txtmessage);
if($return ==false)
{
$this->addFlash('danger', 'Erreur lors de l\'envoi du mail');
}
else
{
$this->addFlash('success', 'Le message a été envoyé');
}
return $this->redirect($request->getUri());
}
if($formcontact->isSubmitted() && !$formcontact->isValid())
{
foreach($formcontact->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
return $this->render('homecontact.html.twig', [
'formcontact' => $formcontact->createView(),
]);
}
public function ShowSubscriptions(SessionInterface $session, PaginatorInterface $paginator, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user= $this->getUser();
$editions=array();
if($user!=null)
{
$editions = $this->getDoctrine()->getRepository(BFEdition::class)->findAllSubscriptions($user, true);
}
$session->set('homefavorites', $editions);
$pagination = $paginator->paginate(
$session->get('homefavorites'), /* query NOT result */
$request->query->getInt('page', 1), /*page number*/
10 /*limit per page*/
);
return $this->render('homesubscriptions.html.twig', [
'pagination' => $pagination,
]);
}
public function all(Request $request)
{
$festivals = $this->getDoctrine()
->getRepository(BFFestival::class)
->findAllOrderByName();
return $this->render('homeall.html.twig', [
'bffestivals' => $festivals,
]);
}
public function AllChallenges(SessionInterface $session, PaginatorInterface $paginator, Request $request)
{
$challenges = $this->getDoctrine()
->getRepository(BFChallenge::class)
->findAllOrderByName();
$session->set('allchallenges', $challenges);
$pagination = $paginator->paginate(
$session->get('allchallenges'), /* query NOT result */
$request->query->getInt('page', 1), /*page number*/
10 /*limit per page*/
);
return $this->render('homeallchallenges.html.twig', [
'pagination' => $pagination,
]);
}
private function ClearUserResetPassword(BFUser $bfuser)
{
//get bfreset from user id
$bfresetpassword = $this->getDoctrine()->getRepository(BFResetPassword::class)->findOneBy(['user'=>$bfuser]);
if($bfresetpassword!=null)
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($bfresetpassword);
$entityManager->flush();
}
}
}
?>