src/Controller/SecurityController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use GuzzleHttp\Client;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  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("/login", name="app_login")
  13.      */
  14.     public function login(AuthenticationUtils $authenticationUtils,Request $request): Response
  15.     {
  16.          if ($this->getUser()) {
  17.              return $this->redirectToRoute('dashboard_index');
  18.          }
  19.         // get the login error if there is one
  20.         $error $authenticationUtils->getLastAuthenticationError();
  21.         // last username entered by the user
  22.         $lastUsername $authenticationUtils->getLastUsername();
  23.         $client = new Client(['base_uri' => 'https://api.quotable.io''verify' => false]);
  24.         try {
  25.             $response $client->get('random');
  26.             $quote json_decode($response->getBody()->getContents(), true);
  27.         } catch (\Throwable $e) {
  28.             // Just ignore errors
  29.         }
  30.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error'quote' => $quote ?? null]);
  31.     }
  32.     /**
  33.      * @Route("/logout", name="app_logout", schemes={"https"})
  34.      */
  35.     public function logout(): void
  36.     {
  37.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  38.     }
  39. }