src/Controller/LoginController.php line 18

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\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. class LoginController extends AbstractController
  8. {
  9.     /**
  10.     * @Route("/login", name="login_index")
  11.     */
  12.     public function index(AuthenticationUtils $authenticationUtils): Response
  13.     {
  14.         if($this->getUser()) return $this->redirectToRoute('sonata_admin_dashboard');
  15.         // get the login error if there is one
  16.         $error $authenticationUtils->getLastAuthenticationError();
  17.         // last username entered by the user
  18.         $lastUsername $authenticationUtils->getLastUsername();
  19.         return $this->render('login/index.html.twig', [
  20.             'last_username' => $lastUsername,
  21.             'error'         => $error,
  22.         ]);
  23.     }
  24.     /**
  25.     * @Route("/logout", name="login_logout", methods={"GET"})
  26.     */
  27.     public function logout(): void
  28.     {
  29.         // controller can be blank: it will never be called!
  30.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  31.     }
  32. }