vendor/pec-platform/user-bundle/Controller/LoginController.php line 27

Open in your IDE?
  1. <?php
  2. namespace Pec\Bundle\UserBundle\Controller;
  3. use Pec\Bundle\UserBundle\DependencyInjection\Configuration;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. use Symfony\Component\Security\Http\Util\TargetPathTrait;
  10. class LoginController extends AbstractController {
  11.     use TargetPathTrait;
  12.     public const ALLOW_REGISTRATION Configuration::PREFIX '.' 'allow_registration';
  13.     public const ALLOW_PASSWORD_RESET Configuration::PREFIX '.' 'allow_password_reset';
  14.     public const ADDITIONAL_LOGINS Configuration::PREFIX '.' 'additional_logins';
  15.     /**
  16.      * @param AuthenticationUtils   $authenticationUtils
  17.      * @param ParameterBagInterface $parameterBag
  18.      * @return Response
  19.      */
  20.     #[Route("/login"name"pec_user_login")]
  21.     public function index(AuthenticationUtils $authenticationUtilsParameterBagInterface $parameterBag): Response {
  22.         if($this->getUser()) {
  23.             return $this->redirectToRoute('pec_dashboard_homepage');
  24.         }
  25.         // get the login error if there is one
  26.         $error $authenticationUtils->getLastAuthenticationError();
  27.         // last username entered by the user
  28.         $lastUsername $authenticationUtils->getLastUsername();
  29.         return $this->render('@PecUser/login/index.html.twig', [
  30.             'last_username'      => $lastUsername,
  31.             'error'              => $error,
  32.             'allowPasswordReset' => $parameterBag->has(self::ALLOW_PASSWORD_RESET) ? $parameterBag->get(self::ALLOW_PASSWORD_RESET) : false,
  33.             'allowRegistration'  => $parameterBag->has(self::ALLOW_REGISTRATION) ? $parameterBag->get(self::ALLOW_REGISTRATION) : false,
  34.             'additionalLogins'   => $parameterBag->has(self::ADDITIONAL_LOGINS) ? $parameterBag->get(self::ADDITIONAL_LOGINS) : [],
  35.             'templates'          => [],
  36.             'backgroundImages'   => [],
  37.         ]);
  38.     }
  39.     #[Route('/logout'name'pec_user_logout'methods: ['GET'])]
  40.     public function logout(): Response {
  41.         // controller can be blank: it will never be called!
  42.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  43.     }
  44. }