<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
//
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\ReaVideo;
use App\Entity\UtilisateurVideo;
use App\Entity\TypeVideo;
class ReaVideoController extends AbstractController
{
/**
* @Route("/rea_video", name="rea_video")
* @param Request $request
*
* @return Response
*/
public function index(ManagerRegistry $doctrine, Request $request)
{
// Datas
$em = $doctrine->getManager();
$userValid = false;
$message = "";
// Vérification connection utilisateur
if( $request->getContent() ){
if( $request->get('login') !== "" && $request->get('password') !== "" ){
// 1 - reccupérer les informations de connexion
$login = $request->get('login');
$password = $request->get('password');
// dump($login, $password);
// die();
// 2 - Get user
$user = $em->getRepository(UtilisateurVideo::class)->findOneBy([
'name' => $login,
'mot_de_passe' => $password
]);
// dump($user);
if( $user !== null ){
// 3 - Verif durée
if( $user->checkDuree() ){
$userValid = true;
}else{
$message = "Votre periode n'est plus valide";
}
}else{
$message = "Vos identifiants de connexion sont incorrect, merci de revenir vers Equinoxes!";
}
}else{
$message = "Merci de renseigner un login et un mot de passe !";
}
// dump($message);
}
// Si l'utilisateur est valide (login + durée)
if( $userValid == true ){
// Affichage réalisations
$realisations = $em->getRepository(ReaVideo::class)->findAll();
$categories = $em->getRepository(TypeVideo::class)->findAll();
return $this->render('rea_video/index.html.twig', [
'realisations' => $realisations,
'categories' => $categories,
'controller_name' => 'ReaVideoController',
]);
}else{
// Affichage formulaire
return $this->render('rea_video/formConnexion.html.twig', [
'message' => $message,
'controller_name' => 'ReaVideoController',
]);
}
}
}
?>