src/Controller/SecurityController.php line 30

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