src/Controller/SecurityController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Controller\CoreController;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpKernel\Exception\HttpException;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use App\Enum\AppConst;
  14. class SecurityController extends CoreController
  15. {
  16.     /**
  17.      * Login Back
  18.      *
  19.      * @Route("/back/login", name="app_login")
  20.      */
  21.     public function login(AuthenticationUtils $authenticationUtils): Response
  22.     {
  23.         // get the login error if there is one
  24.         $error $authenticationUtils->getLastAuthenticationError();
  25.         $error_login  $this->requestStack->getSession()->get(AppConst::ERROR_LOGIN);
  26.         // last username entered by the user
  27.         $lastUsername $authenticationUtils->getLastUsername();
  28.         return $this->render('security/login/login.html.twig', [
  29.             'last_username' => $lastUsername,
  30.             'error' => $error,
  31.             'error_login' => $error_login]);
  32.     }
  33.     /**
  34.      * Login Front
  35.      *
  36.      * @Route("/{myflix}/login", name="app_login_membre", methods={"GET","POST"})
  37.      */
  38.     public function loginMembre($myflixAuthenticationUtils $authenticationUtils): Response
  39.     {
  40.         $getMyflix $this->repository->MyflixRepository->findOneBy(['slug' => $myflix]);
  41.         if(!$getMyflix){
  42.             return $this->redirectToRoute('error_404');
  43.         }
  44.         // get the login error if there is one
  45.         $error $authenticationUtils->getLastAuthenticationError();
  46.         // last username entered by the user
  47.         $lastUsername $authenticationUtils->getLastUsername();
  48.         if($this->getUser()){
  49.             return $this->redirectToRoute('app_path_front', ['myflix' => $myflix]);
  50.         }
  51.         $capsule $this->requestStack->getCurrentRequest()->query->get('capsule');
  52.         return $this->render('security/login/login_member.html.twig', [
  53.             'last_username' => $lastUsername,
  54.             'error' => $error,
  55.             'capsule' => $capsule]);
  56.     }
  57.     /**
  58.      * @Route("/back/logout", name="app_logout")
  59.      */
  60.     public function logout()
  61.     {
  62.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  63.     }
  64. }