src/Controller/AuthController.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\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\Session\Session;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class AuthController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/login", name="app_login")
  14.      */
  15.     public function login(AuthenticationUtils $authenticationUtilsRequest $requestSession $session): Response
  16.     {
  17.         if ($this->getUser()) {
  18.             return $this->redirectToRoute('dashboard');
  19.         }
  20.         // get the login error if there is one
  21.         $error $authenticationUtils->getLastAuthenticationError();
  22.         if ($session->get('google_oauth')) {
  23.             $error = new CustomUserMessageAuthenticationException($session->get('google_oauth'));
  24.             $session->remove('google_oauth');
  25.         }
  26.         // last username entered by the user
  27.         $lastUsername $authenticationUtils->getLastUsername();
  28.         return $this->render(
  29.             'security/login.html.twig',
  30.             [
  31.                 'last_username' => $lastUsername,
  32.                 'error' => $error,
  33.             ]
  34.         );
  35.     }
  36.     /**
  37.      * @Route("/logout", name="app_logout")
  38.      */
  39.     public function logout()
  40.     {
  41.         throw new \LogicException(
  42.             'This method can be blank - it will be intercepted by the logout key on your firewall.'
  43.         );
  44.     }
  45. }