src/Controller/SecurityController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Form\RegistrationFormType;
  5. use http\Message;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends AbstractController
  11. {
  12.     #[Route(path'/connexion'name'app_login')]
  13.     public function login(AuthenticationUtils $authenticationUtils): Response
  14.     {
  15.         $user = new User();
  16.         $form $this->createForm(RegistrationFormType::class, $user);
  17.         // get the login error if there is one
  18.         $error $authenticationUtils->getLastAuthenticationError();
  19.         // last username entered by the user
  20.         $lastUsername $authenticationUtils->getLastUsername();
  21.         return $this->render('security\login.html.twig', [
  22.             'last_username' => $lastUsername,
  23.             'error' => $error,
  24.             'registrationForm' => $form->createView(),
  25.         ]);
  26.     }
  27.     #[Route(path'/login'name'app_login_home')]
  28.     public function loginByHome(AuthenticationUtils $authenticationUtils): Response
  29.     {
  30.         $user = new User();
  31.         $form $this->createForm(RegistrationFormType::class, $user);
  32.         // get the login error if there is one
  33.         $error $authenticationUtils->getLastAuthenticationError();
  34.         // last username entered by the user
  35.         $lastUsername $authenticationUtils->getLastUsername();
  36.         return $this->render('security/login.html.twig', [
  37.             'last_username' => $lastUsername,
  38.             'error' => $error,
  39.             'registrationForm' => $form->createView(),
  40.         ]);
  41.     }
  42.     #[Route(path'/logout'name'app_logout')]
  43.     public function logout(): void
  44.     {
  45.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  46.     }
  47. }