src/Controller/LoginController.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Smakmedia\Controller;
  4. use Exception;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class LoginController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/login", name="login")
  14.      */
  15.     public function login(AuthenticationUtils $authenticationUtils): Response
  16.     {
  17.         if ($this->isGranted('ROLE_USER')) {
  18.             return $this->redirectToRoute('dashboard');
  19.         }
  20.         $error $authenticationUtils->getLastAuthenticationError();
  21.         $username $authenticationUtils->getLastUsername();
  22.         return $this->render('login.html.twig', [
  23.             'username' => $username,
  24.             'error' => $error,
  25.         ]);
  26.     }
  27.     /**
  28.      * @IsGranted("ROLE_USER")
  29.      *
  30.      * @Route("/logout", name="logout", methods={"GET"})
  31.      */
  32.     public function logout()
  33.     {
  34.         // controller can be blank: it will never be executed!
  35.         throw new Exception('Don\'t forget to activate logout in security.yaml');
  36.     }
  37. }