<?php
namespace App\Controller;
use Algolia\AlgoliaSearch\SearchClient;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Algolia\SearchBundle\SearchService;
use Symfony\Component\HttpFoundation\Request;
class SecurityController extends AbstractController
{
public function __construct(EntityManagerInterface $em, RequestStack $request, SearchService $search_service)
{
$this->em = $em;
$this->host = $request->getCurrentRequest()->headers->get('host');
$this->params['show_viewed_products'] = true;
$this->search_service = $search_service;
}
/**
* @Route("/", name="app_main", priority=10)
*/
public function main(Request $request){
return $this->redirectToRoute('app_login');
}
/**
* @Route("/login", name="app_login", priority=10)
*/
public function login(AuthenticationUtils $authenticationUtils, SearchClient $search_client): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
$this->params['is_pdf'] = 0;
$this->params['error'] = $error ? $error->getMessage() : NULL;
//$this->params['lang'] = 'fr';
$this->params['show_screen_loader'] = 1;
$this->params['csrf_token_intention'] = 'authenticate';
return $this->render('@EasyAdmin/page/login.html.twig', [
// parameters usually defined in Symfony login forms
'error' => $error,
'last_username' => $lastUsername,
// OPTIONAL parameters to customize the login form:
// the translation_domain to use (define this option only if you are
// rendering the login template in a regular Symfony controller; when
// rendering it from an EasyAdmin Dashboard this is automatically set to
// the same domain as the rest of the Dashboard)
'translation_domain' => 'admin',
// the title visible above the login form (define this option only if you are
// rendering the login template in a regular Symfony controller; when rendering
// it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
'page_title' => 'Bookdoreille',
// the string used to generate the CSRF token. If you don't define
// this parameter, the login form won't include a CSRF token
'csrf_token_intention' => 'authenticate',
// the URL users are redirected to after the login (default: '/admin')
'target_path' => $this->generateUrl('admin'),
// the label displayed for the username form field (the |trans filter is applied to it)
'username_label' => 'Username',
// the label displayed for the password form field (the |trans filter is applied to it)
'password_label' => 'Mot de passe',
// the label displayed for the Sign In form button (the |trans filter is applied to it)
'sign_in_label' => 'Se connecter',
// the 'name' HTML attribute of the <input> used for the username field (default: '_username')
'username_parameter' => 'username',
// the 'name' HTML attribute of the <input> used for the password field (default: '_password')
'password_parameter' => 'password',
]);
}
/**
* @Route("/logout", name="app_logout", priority=10)
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}