<?php
namespace App\Controller;
use App\Entity\Blog;
use App\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\Persistence\ManagerRegistry;
use App\Form\ConnexionUserType;
use App\Form\loginType;
use App\Entity\ConnexionUser;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use App\Entity\EvenementFormulaire;
use App\Entity\PayementMethod;
class ConnexionController extends AbstractController
{
private $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function index(ManagerRegistry $doctrine,Request $request)
{
$erreur="";
$verif=true;
$messageSuccess="";
$entityManager = $doctrine->getManager();
$article = new ConnexionUser();
$form = $this->createForm(ConnexionUserType::class, $article);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if(Empty($article->getNom()))
{
$erreur.="Nom Invalide <br>";
$verif=false;
}
else if(strlen($article->getNom())<4 || strlen($article->getNom())>30)
{
$erreur.="Nom Invalide <br>";
$verif=false;
}
else
{
$verif=true;
}
if(Empty($article->getPrenom()))
{
$erreur.="Prenom Invalide <br>";
$verif=false;
}
else if(strlen($article->getPrenom())<4 || strlen($article->getPrenom())>30)
{
$erreur.="Prenom Invalide <br>";
$verif=false;
}
else
{
$verif=true;
}
if(Empty($article->getEmail()))
{
$erreur.="Email Invalide <br>";
$verif=false;
}
else if(strlen($article->getEmail())<7 || strlen($article->getEmail())>30)
{
$erreur.="Email Invalide <br>";
$verif=false;
}
else
{
$verif=true;
}
if(Empty($article->getPassword()))
{
$erreur.="Password Invalide <br>";
$verif=false;
}
else if(strlen($article->getPassword())<7 || strlen($article->getPassword())>30)
{
$erreur.="Password Invalide <br>";
$verif=false;
}else
{
$verif=true;
}
/**/
if(strlen($erreur)==0)
{
$repository = $doctrine->getRepository(ConnexionUser::class);
$p = $repository->findBy(
['email' => $article->getEmail()]
);
if(count($p)>0)
{
$erreur.= "Email dja existe ";
}
else
{
$entityManager->persist($article);
$entityManager->flush();
$messageSuccess="Votre compte a été créé avec succès";
}
/* $entityManager->persist($article);
$entityManager->flush();*/
}
}
return $this->render('login/login.html.twig', array(
'form' => $form->createView(),'erreur'=>$erreur,'message'=>$messageSuccess
));
}
public function index2(ManagerRegistry $doctrine,Request $request)
{
$erreur="";
$verif=true;
$messageSuccess="";
$entityManager = $doctrine->getManager();
$article = new ConnexionUser();
$form = $this->createForm(ConnexionUserType::class, $article);
$form->handleRequest($request);
$email=$_POST['email'];
$password=$_POST['password'];
$type=$_POST['type'];
$nom=$_POST['nom'];
$prenom=$_POST['prenom'];
$phone=$_POST['phone'];
if(Empty($nom))
{
$erreur.="Nom Invalide <br>";
$verif=false;
}
else if(strlen($nom)<4 || strlen($nom)>30)
{
$erreur.="Nom Invalide <br>";
$verif=false;
}
else
{
$verif=true;
}
if(Empty($nom))
{
$erreur.="Prenom Invalide <br>";
$verif=false;
}
else if(strlen($nom)<4 || strlen($nom)>30)
{
$erreur.="Prenom Invalide <br>";
$verif=false;
}
else
{
$verif=true;
}
if(Empty($email))
{
$erreur.="Email Invalide <br>";
$verif=false;
}
else if(strlen($email)<7 || strlen($email)>30)
{
$erreur.="Email Invalide <br>";
$verif=false;
}
else
{
$verif=true;
}
if(Empty($password))
{
$erreur.="Password Invalide <br>";
$verif=false;
}
else if(strlen($password)<7 || strlen($password)>30)
{
$erreur.="Password Invalide <br>";
$verif=false;
}else
{
$verif=true;
}
/**/
if(strlen($erreur)==0)
{
$repository = $doctrine->getRepository(ConnexionUser::class);
$p = $repository->findBy(
['email' => $email]
);
if(count($p)>0)
{
$erreur.= "Email dja existe ";
}
else
{
$article = new ConnexionUser();
$article->setEmail($email);
$article->setNom($nom);
$article->setPrenom($prenom);
$article->setType($type);
$article->setPhone($phone);
$article->setPassword($password);
$entityManager->persist($article);
$entityManager->flush();
$session = $this->requestStack->getSession();
$session->set('email', $email);
$session->set('password', $password);
$messageSuccess="Votre compte a été créé avec succès";
}
/* $entityManager->persist($article);
$entityManager->flush();*/
}
$err='{"erreur": "'.$erreur.'", "message":"'.$messageSuccess.'"}';
echo $err;exit();
}
public function connexion(ManagerRegistry $doctrine,Request $request)
{
$erreur="";
$verif=true;
$entityManager = $doctrine->getManager();
$article = new ConnexionUser();
$form = $this->createForm(loginType::class, $article);
$form->handleRequest($request);
/***** verification les champ */
if ($form->isSubmitted() && $form->isValid()) {
if(Empty($article->getEmail()))
{
$erreur.="Email Invalide <br>";
$verif=false;
}
else if(strlen($article->getEmail())<7 || strlen($article->getEmail())>30)
{
$erreur.="Email Invalide <br>";
$verif=false;
}
else
{
$verif=true;
}
if(Empty($article->getPassword()))
{
$erreur.="Password Invalide <br>";
$verif=false;
}
else if(strlen($article->getPassword())<7 || strlen($article->getPassword())>30)
{
$erreur.="Password Invalide <br>";
$verif=false;
}else
{
$verif=true;
}
$repository = $doctrine->getRepository(ConnexionUser::class);
$p = $repository->findBy(
['email' => $article->getEmail(),'password'=>$article->getPassword()]
);
if(count($p)>0)
{
$session = $this->requestStack->getSession();
$session->set('email', $article->getEmail());
$session->set('password', $article->getPassword());
return $this->redirectToRoute('profile_user');
}
else
{
if($erreur=="")
{
$erreur.= "Email ou mot de passe invalide ! ";
}
}
}
return $this->render('login/connexion.html.twig', array(
'form' => $form->createView(),'erreur'=>$erreur
));
}
public function connexionPaiment(ManagerRegistry $doctrine,Request $request)
{
$email=$_POST['email'];
$password=$_POST['password'];
$repository = $doctrine->getRepository(ConnexionUser::class);
$p = $repository->findBy(
['email' => $email,'password'=>$password]
);
if(count($p)>0)
{
$session = $this->requestStack->getSession();
$session->set('email', $email);
$session->set('password', $password);
echo "1";
}
else
{
echo "0";
}
exit();
}
public function connexionPaimentPhone(ManagerRegistry $doctrine,Request $request)
{
$phone = $_POST['phone'];
$repository = $this->getDoctrine()->getRepository(PayementMethod::class);
$px = $repository->findBy(['phone' => $phone, 'pai' => true]);
$repository = $doctrine->getRepository(EvenementFormulaire::class);
$p = $repository->findBy(
['phone' => $phone]
);
if (count($px) > 0) {
echo "-1";
}
else if(count($p)>0)
{
echo "1";
$session = $this->requestStack->getSession();
$session->set('evenementspecifique', $phone);
}
else
{
echo "0";
}
exit();
}
}