src/Controller/Front/IndexController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Repository\CompetitionRepository;
  4. use Symfony\Component\Security\Core\Security;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class IndexController extends AbstractController
  10. {
  11.     #[Route('/'name'index')]
  12.     public function index(AuthenticationUtils $authenticationUtilsCompetitionRepository $competitionRepositorySecurity $security): Response
  13.     {
  14.         $user $security->getUser();
  15.         //competitions
  16.         $competitions $competitionRepository->findByDateActive();
  17.         if($user) {
  18.             return $this->render('Front/index/index.html.twig', [
  19.                 'competitions' => $competitions,
  20.             ]);
  21.         } else {
  22.             //login
  23.             $error $authenticationUtils->getLastAuthenticationError();
  24.             $lastUsername $authenticationUtils->getLastUsername();
  25.             return $this->render('Front/index/index.html.twig', [
  26.                 'last_username' => $lastUsername
  27.                 'error' => $error,
  28.                 'competitions' => $competitions,
  29.             ]);
  30.         }   
  31.     }
  32. }