src/Controller/LoginController.php line 17

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="app_login")
  11.      * @param AuthenticationUtils $authenticationUtils
  12.      * @return Response
  13.      */
  14.     public function index(AuthenticationUtils $authenticationUtils): Response
  15.     {
  16.         $error $authenticationUtils->getLastAuthenticationError();
  17.         $lastUsername $authenticationUtils->getLastUsername();
  18.         return $this->render('login/index.html.twig', [
  19.             'last_username' => $lastUsername,
  20.             'error' => $error
  21.         ]);
  22.     }
  23.     /**
  24.      * @Route(path="/login_success", name="login_success")
  25.      * @return Response
  26.      */
  27.     public function loginSuccess(): Response
  28.     {
  29.         $user $this->getUser();
  30.         if (!$user->isIsSpecial()) {
  31.             return $this->redirectToRoute('dashboard');
  32.         } else {
  33.             return $this->redirectToRoute('app_special_index');
  34.         }
  35.     }
  36.     /**
  37.      * @Route("/logout", name="app_logout", methods={"GET"})
  38.      * @throws \Exception
  39.      */
  40.     public function logout(): void
  41.     {
  42.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  43.     }
  44. }