src/Controller/Account/SecurityController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Account;
  3. use CoreShop\Bundle\CustomerBundle\Form\Type\CustomerLoginType;
  4. use CoreShop\Bundle\FrontendBundle\Controller\FrontendController;
  5. use CoreShop\Component\Core\Context\ShopperContextInterface;
  6. use Symfony\Component\Form\FormFactoryInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends FrontendController
  11. {
  12.     public function __construct(
  13.         protected AuthenticationUtils $authenticationUtils,
  14.         protected FormFactoryInterface $formFactory,
  15.         protected ShopperContextInterface $shopperContext,
  16.     ) {
  17.     }
  18.     public function loginAction(Request $request): Response
  19.     {
  20.         if ($this->shopperContext->hasCustomer()) {
  21.             return $this->redirect('/');
  22.         }
  23.         $lastError = $this->authenticationUtils->getLastAuthenticationError();
  24.         $lastUsername = $this->authenticationUtils->getLastUsername();
  25.         $form = $this->formFactory->createNamed('', CustomerLoginType::class);
  26.         $fullpage = $this->getParameterFromRequest($request, 'fullpage', true);
  27.         return $this->render($fullpage ? 'account/login.html.twig' : 'basket/customer/_login.html.twig', [
  28.             'form' => $form->createView(),
  29.             'last_username' => $lastUsername,
  30.             'last_error' => $lastError,
  31.             'target' => $this->getParameterFromRequest($request, 'target', null),
  32.             'failure' => $this->getParameterFromRequest($request, 'failure', null),
  33.         ]);
  34.     }
  35. }