src/Controller/SecurityController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Persistence\ManagerRegistry;
  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("/", name="app_login")
  13. */
  14. public function login(AuthenticationUtils $authenticationUtils, ManagerRegistry $doctrine): Response
  15. {
  16. // get the login error if there is one
  17. $error = $authenticationUtils->getLastAuthenticationError();
  18. // last username entered by the user
  19. $lastUsername = $authenticationUtils->getLastUsername();
  20. $name = '';
  21. if ($lastUsername)
  22. {
  23. $userRepo = new UserRepository($doctrine);
  24. if ($currentUser = $userRepo->getByLogin($lastUsername)) {
  25. $name = $currentUser->getName();
  26. }
  27. }
  28. return $this->render('security/login.html.twig', ['last_username' => $name, 'error' => $error]);
  29. }
  30. /**
  31. * @Route("/logout", name="app_logout")
  32. */
  33. public function logout()
  34. {
  35. throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  36. }
  37. }