src/Controller/SecurityController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Form\RegisterType;
  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.     /**
  12.      * @Route("/login", name="app_login")
  13.      */
  14.     public function login(AuthenticationUtils $authenticationUtils): Response
  15.     {
  16.         // if ($this->getUser()) {
  17.         //     return $this->redirectToRoute('target_path');
  18.         // }
  19.         // get the login error if there is one
  20.         $error $authenticationUtils->getLastAuthenticationError();
  21.         // last username entered by the user
  22.         $lastUsername $authenticationUtils->getLastUsername();
  23.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  24.     }
  25.     /**
  26.      * @Route("/connexion", name="front_login")
  27.      */
  28.     public function connexion(AuthenticationUtils $authenticationUtils): Response
  29.     {
  30.         // if ($this->getUser()) {
  31.         //     return $this->redirectToRoute('target_path');
  32.         // }
  33.         $user = new User();
  34.         $route $this->generateUrl('front_inscription');
  35.         $form $this->createForm(RegisterType::class, $user, [
  36.             'action' => $route,
  37.             'method' => 'POST',
  38.         ]);
  39.         // get the login error if there is one
  40.         $error $authenticationUtils->getLastAuthenticationError();
  41.         // last username entered by the user
  42.         $lastUsername $authenticationUtils->getLastUsername();
  43.         return $this->render('security/front_login.html.twig', ['last_username' => $lastUsername'error' => $error'form' => $form->createView()]);
  44.     }
  45.     /**
  46.      * @Route("/logout", name="app_logout")
  47.      */
  48.     public function logout()
  49.     {
  50.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  51.     }
  52. }