src/Controller/SecurityController.php line 25

  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\SettingsRepository;
  4. use Exception;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends AbstractController
  11. {
  12.     #[Route(path'/login'name'login_non_locale')]
  13.     public function login_non_locale(Request $request): Response
  14.     {
  15.         return $this->redirectToRoute("login",["_locale"=>$request->getLocale()]);
  16.     }
  17.     
  18.     #[Route(path'/{_locale}/login'name'login')]
  19.     public function login(AuthenticationUtils $authenticationUtils,SettingsRepository $settingsRepository): Response
  20.     {
  21.         $error $authenticationUtils->getLastAuthenticationError();
  22.         $lastUsername $authenticationUtils->getLastUsername();
  23.         $settingsMain $settingsRepository->findOneBy(["code"=>"main"]);
  24.         $twigParams = [
  25.             // parameters usually defined in Symfony login forms
  26.             'error' => $error,
  27.             'last_username' => $lastUsername,
  28.             // OPTIONAL parameters to customize the login form:
  29.             // the translation_domain to use (define this option only if you are
  30.             // rendering the login template in a regular Symfony controller; when
  31.             // rendering it from an EasyAdmin Dashboard this is automatically set to
  32.             // the same domain as the rest of the Dashboard)
  33.             'translation_domain' => 'admin',
  34.             // by default EasyAdmin displays a black square as its default favicon;
  35.             // use this method to display a custom favicon: the given path is passed
  36.             // "as is" to the Twig asset() function:
  37.             // <link rel="shortcut icon" href="{{ asset('...') }}">
  38.              'background_body'=>"url('/themes/".strtolower($settingsMain->getAssetFolderName())."/admin/images/bg-body.jpg')",
  39.             'favicon_path' => "/themes/".strtolower($settingsMain->getAssetFolderName())."/admin/images/favicon.png",
  40.             // the title visible above the login form (define this option only if you are
  41.             // rendering the login template in a regular Symfony controller; when rendering
  42.             // it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
  43.             'page_title' => '<img width="200" class="mb-3 mt-5" src="/themes/'.strtolower($settingsMain->getAssetFolderName()).'/images/logo.png"  />',
  44.             // the string used to generate the CSRF token. If you don't define
  45.             // this parameter, the login form won't include a CSRF token
  46.             'csrf_token_intention' => 'authenticate',
  47.             // the URL users are redirected to after the login (default: '/admin')
  48.             //'target_path' => $this->generateUrl('admin'),
  49.             // the label displayed for the username form field (the |trans filter is applied to it)
  50.             'username_label' => 'Nom d\'utilisateur',
  51.             // the label displayed for the password form field (the |trans filter is applied to it)
  52.             'password_label' => 'Mot de passe',
  53.             // the label displayed for the Sign In form button (the |trans filter is applied to it)
  54.             'sign_in_label' => 'Se connecter',
  55.             // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  56.             'username_parameter' => 'username',
  57.             // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  58.             'password_parameter' => 'password',
  59.             // whether to enable or not the "forgot password?" link (default: false)
  60.             'forgot_password_enabled' => false,
  61.             // the path (i.e. a relative or absolute URL) to visit when clicking the "forgot password?" link (default: '#')
  62.             //'forgot_password_path' => $this->generateUrl('...', ['...' => '...']),
  63.             // the label displayed for the "forgot password?" link (the |trans filter is applied to it)
  64.             'forgot_password_label' => 'Forgot your password?',
  65.             // whether to enable or not the "remember me" checkbox (default: false)
  66.             'remember_me_enabled' => true,
  67.             // remember me name form field (default: '_remember_me')
  68.             'remember_me_parameter' => 'remember_me',
  69.             // whether to check by default the "remember me" checkbox (default: false)
  70.             'remember_me_checked' => false,
  71.             // the label displayed for the remember me checkbox (the |trans filter is applied to it)
  72.             'remember_me_label' => 'Se souvenir de moi',
  73.             ];
  74.             return $this->render('@Flexy/FrontBundle/Themes/'.$settingsMain->getFrontTheme().'/templates/admin/easyadmin/page/login.html.twig'$twigParams);
  75.         try{
  76.             
  77.         }catch(Exception $ex){
  78.             return $this->render('@EasyAdmin/page/login.html.twig'$twigParams);
  79.         }
  80.     }
  81.     #[Route(path'/{_locale}/logout'name'app_logout')]
  82.     public function logout(): never
  83.     {
  84.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  85.     }
  86. }