<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Company;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*
* @param AuthenticationUtils $authenticationUtils
*
* @return Response
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
/**
* @Route("/logout", name="app_logout")
*
* @return Response
*/
public function logout()
{
return $this->render('security/login.html.twig', ['last_username' => '', 'error' => '']);
}
/**
* @Route("/api/token/{id}/{token}", name="app_api")
*
* @param int $id
* @param EntityManagerInterface $em
*
* @return Response
*/
public function autoLogin(int $id, EntityManagerInterface $em): Response
{
$repository = $em->getRepository(Company::class);
if ($company = $repository->find($id)) {
$this->get('session')->set('currentCompanyId', $company->getId());
return $this->redirectToRoute('company_edit', ['id' => $company->getId()]);
}
return $this->redirectToRoute('app_logout');
}
}