src/Controller/SecurityController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Algolia\AlgoliaSearch\SearchClient;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. use Algolia\SearchBundle\SearchService;
  11. use Symfony\Component\HttpFoundation\Request;
  12. class SecurityController extends AbstractController
  13. {   
  14.     public function __construct(EntityManagerInterface $emRequestStack $requestSearchService $search_service)
  15.     {
  16.         $this->em $em;
  17.         $this->host $request->getCurrentRequest()->headers->get('host');
  18.         $this->params['show_viewed_products'] = true;
  19.         $this->search_service $search_service;
  20.     }
  21.     /**
  22.      * @Route("/", name="app_main", priority=10)
  23.      */
  24.     public function main(Request $request){
  25.         return $this->redirectToRoute('app_login');
  26.     }
  27.     /**
  28.      * @Route("/login", name="app_login", priority=10)
  29.      */
  30.     public function login(AuthenticationUtils $authenticationUtilsSearchClient $search_client): Response
  31.     {
  32.         $error $authenticationUtils->getLastAuthenticationError();
  33.         $lastUsername $authenticationUtils->getLastUsername();
  34.         $this->params['is_pdf'] = 0;
  35.         $this->params['error'] = $error $error->getMessage() : NULL;
  36.         //$this->params['lang'] = 'fr';
  37.         $this->params['show_screen_loader'] = 1;
  38.         $this->params['csrf_token_intention'] = 'authenticate';
  39.         return $this->render('@EasyAdmin/page/login.html.twig', [
  40.             // parameters usually defined in Symfony login forms
  41.             'error' => $error,
  42.             'last_username' => $lastUsername,
  43.             // OPTIONAL parameters to customize the login form:
  44.             // the translation_domain to use (define this option only if you are
  45.             // rendering the login template in a regular Symfony controller; when
  46.             // rendering it from an EasyAdmin Dashboard this is automatically set to
  47.             // the same domain as the rest of the Dashboard)
  48.             'translation_domain' => 'admin',
  49.             // the title visible above the login form (define this option only if you are
  50.             // rendering the login template in a regular Symfony controller; when rendering
  51.             // it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
  52.             'page_title' => 'Bookdoreille',
  53.             // the string used to generate the CSRF token. If you don't define
  54.             // this parameter, the login form won't include a CSRF token
  55.             'csrf_token_intention' => 'authenticate',
  56.             // the URL users are redirected to after the login (default: '/admin')
  57.             'target_path' => $this->generateUrl('admin'),
  58.             // the label displayed for the username form field (the |trans filter is applied to it)
  59.             'username_label' => 'Username',
  60.             // the label displayed for the password form field (the |trans filter is applied to it)
  61.             'password_label' => 'Mot de passe',
  62.             // the label displayed for the Sign In form button (the |trans filter is applied to it)
  63.             'sign_in_label' => 'Se connecter',
  64.             // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  65.             'username_parameter' => 'username',
  66.             // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  67.             'password_parameter' => 'password',
  68.         ]);
  69.     }
  70.     /**
  71.      * @Route("/logout", name="app_logout", priority=10)
  72.      */
  73.     public function logout()
  74.     {
  75.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  76.     }
  77. }