src/Controller/Auth/App/SecurityController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Auth\App;
  3. use App\Entity\App\User;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. /**
  9. * Class SecurityController
  10. *
  11. * @package App\Controller
  12. */
  13. class SecurityController extends AbstractController
  14. {
  15. /**
  16. * @Route("/{_locale}/login", name="login", requirements={"_locale": "\w{2}"})
  17. *
  18. * @param AuthenticationUtils $authenticationUtils
  19. *
  20. * @return Response
  21. */
  22. public function login(AuthenticationUtils $authenticationUtils): Response
  23. {
  24. if($this->getUser() instanceof User) {
  25. return $this->redirectToRoute('public_index');
  26. }
  27. // get the login error if there is one
  28. $error = $authenticationUtils->getLastAuthenticationError();
  29. // last username entered by the user
  30. $lastUsername = $authenticationUtils->getLastUsername();
  31. return $this->render('Auth/App/login.html.twig', [
  32. 'last_username' => $lastUsername,
  33. 'error' => $error
  34. ]);
  35. }
  36. /**
  37. * @Route("/login")
  38. *
  39. * @return Response
  40. */
  41. public function redirectToLogin()
  42. {
  43. if($this->getUser() instanceof User) {
  44. return $this->redirectToRoute('public_index');
  45. }
  46. return $this->redirectToRoute('login');
  47. }
  48. /**
  49. * @Route("/logout", name="logout", methods={"GET"})
  50. */
  51. public function logout()
  52. {
  53. }
  54. }