src/Controller/SecurityController.php line 21

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. use Doctrine\ORM\EntityManagerInterface;
  8. use App\Entity\Company;
  9. class SecurityController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/login", name="app_login")
  13.      *
  14.      * @param AuthenticationUtils $authenticationUtils
  15.      *
  16.      * @return Response
  17.      */
  18.     public function login(AuthenticationUtils $authenticationUtils): Response
  19.     {
  20.         $error $authenticationUtils->getLastAuthenticationError();
  21.         $lastUsername $authenticationUtils->getLastUsername();
  22.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  23.     }
  24.     /**
  25.      * @Route("/logout", name="app_logout")
  26.      *
  27.      * @return Response
  28.      */
  29.     public function logout()
  30.     {
  31.         return $this->render('security/login.html.twig', ['last_username' => '''error' => '']);
  32.     }
  33.     /**
  34.      * @Route("/api/token/{id}/{token}", name="app_api")
  35.      *
  36.      * @param int $id
  37.      * @param EntityManagerInterface $em
  38.      *
  39.      * @return Response
  40.      */
  41.     public function autoLogin(int $idEntityManagerInterface $em): Response
  42.     {
  43.         $repository $em->getRepository(Company::class);
  44.         if ($company $repository->find($id)) {
  45.             $this->get('session')->set('currentCompanyId'$company->getId());
  46.             return $this->redirectToRoute('company_edit', ['id' => $company->getId()]);
  47.         }
  48.         return $this->redirectToRoute('app_logout');
  49.     }
  50. }