<?php
namespace App\Controller;
use App\Controller\CoreController;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use App\Enum\AppConst;
class SecurityController extends CoreController
{
/**
* Login Back
*
* @Route("/back/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
$error_login = $this->requestStack->getSession()->get(AppConst::ERROR_LOGIN);
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'error_login' => $error_login]);
}
/**
* Login Front
*
* @Route("/{myflix}/login", name="app_login_membre", methods={"GET","POST"})
*/
public function loginMembre($myflix, AuthenticationUtils $authenticationUtils): Response
{
$getMyflix = $this->repository->MyflixRepository->findOneBy(['slug' => $myflix]);
if(!$getMyflix){
return $this->redirectToRoute('error_404');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
if($this->getUser()){
return $this->redirectToRoute('app_path_front', ['myflix' => $myflix]);
}
$capsule = $this->requestStack->getCurrentRequest()->query->get('capsule');
return $this->render('security/login/login_member.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'capsule' => $capsule]);
}
/**
* @Route("/back/logout", name="app_logout")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}