src/Controller/SecurityController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Product;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController
  10. {
  11.     private $entityManager
  12.     public function __construct(EntityManagerInterface $entityManager)
  13.     {
  14.         $this->entityManager $entityManager;
  15.     }
  16.     #[Route(path'/connexion'name'app_login')]
  17.     public function login(AuthenticationUtils $authenticationUtils): Response
  18.     {
  19.         $activity $this->entityManager->getRepository(Product::class)->findAll();
  20.         if ($this->getUser()) {
  21.             return $this->redirectToRoute('app_account');
  22.         }
  23.         // get the login error if there is one
  24.         $error $authenticationUtils->getLastAuthenticationError();
  25.         // last username entered by the user
  26.         $lastUsername $authenticationUtils->getLastUsername();
  27.         return $this->render('security/login.html.twig', [
  28.             'last_username' => $lastUsername,
  29.              'error' => $error,
  30.              'activity' => $activity,
  31.             ]);
  32.     }
  33.     #[Route(path'/deconnexion'name'app_logout')]
  34.     public function logout(): void
  35.     {
  36.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  37.     }
  38. }