<?php
namespace App\Controller\Front;
use App\Repository\CompetitionRepository;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class IndexController extends AbstractController
{
#[Route('/', name: 'index')]
public function index(AuthenticationUtils $authenticationUtils, CompetitionRepository $competitionRepository, Security $security): Response
{
$user = $security->getUser();
//competitions
$competitions = $competitionRepository->findByDateActive();
if($user) {
return $this->render('Front/index/index.html.twig', [
'competitions' => $competitions,
]);
} else {
//login
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('Front/index/index.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'competitions' => $competitions,
]);
}
}
}