src/Controller/Business/SecurityController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Business;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Session\Session;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
  8. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  9. use Symfony\Component\Security\Core\Security;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. class SecurityController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/login", name="app_login")
  15.      */
  16.     public function login(AuthenticationUtils $authenticationUtils): Response
  17.     {
  18.         // if ($this->getUser()) {
  19.         //    $this->redirectToRoute('target_path');
  20.         // }
  21.         // get the login error if there is one
  22.         $error $authenticationUtils->getLastAuthenticationError();
  23.         // last username entered by the user
  24.         $lastUsername $authenticationUtils->getLastUsername();
  25.         return $this->render('admin/security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  26.     }
  27.     /**
  28.      * @Route("/another_device", name="app_another_device")
  29.      */
  30.     public function anotherDevice(Session $sessionTokenStorageInterface $tokenStorage): Response
  31.     {
  32.         $tokenStorage->setToken(null);
  33.         $this->addFlash('danger''Another device has using your account.');
  34.         return $this->redirect($this->generateUrl('app_login'));
  35.     }
  36.     /**
  37.      * @Route("/logout", name="app_logout")
  38.      */
  39.     public function logout()
  40.     {
  41.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  42.     }
  43. }