src/Ecommerce/Controller/SecurityController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Ecommerce\Controller;
  3. use App\Form\Type\DeleteAccountType;
  4. use App\Service\AccountDeleteManager;
  5. use CoreShop\Bundle\CustomerBundle\Form\Type\CustomerLoginType;
  6. use Exception;
  7. use Pimcore\Model\DataObject\CoreShopCustomer;
  8. use Pimcore\Model\DataObject\CoreShopUser;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use CoreShop\Bundle\FrontendBundle\Controller\SecurityController as BaseSecurityController;
  12. class SecurityController extends BaseSecurityController
  13. {
  14.     public function loginAction(Request $request): Response
  15.     {
  16.         if ($this->shopperContext->hasCustomer()) {
  17.             if ($this->getParameterFromRequest($request'renderLayout'true)) {
  18.                 return $this->redirectToRoute('coreshop_index');
  19.             } else {
  20.                 return new Response();
  21.             }
  22.         }
  23.         $lastError $this->authenticationUtils->getLastAuthenticationError();
  24.         return $this->render($this->templateConfigurator->findTemplate(sprintf("Security/%s.html",
  25.             ($this->getParameterFromRequest($request'renderLayout'true) ? "login" "_login-form"))),
  26.             [
  27.                 'form' => $this->formFactory->createNamed(''CustomerLoginType::class)->createView(),
  28.                 'last_username' => $this->authenticationUtils->getLastUsername(),
  29.                 'last_error' => $lastError,
  30.                 'offerRegistration' => $this->getParameterFromRequest($request'offerRegistration'),
  31.                 'target' => $this->getParameterFromRequest($request'target'),
  32.                 'failure' => $this->getParameterFromRequest($request'failure'),
  33.                 'showErrors' => $this->getParameterFromRequest($request'showErrors')
  34.             ]
  35.         );
  36.     }
  37.     public function deleteAccountAction(Request $requestAccountDeleteManager $manager): Response
  38.     {
  39.         $user $this->getUser();
  40.         if (!$user instanceof CoreShopUser) {
  41.             return $this->redirectToRoute('coreshop_index');
  42.         }
  43.         $customer $user->getCustomer();
  44.         if (!$customer instanceof CoreShopCustomer) {
  45.             return $this->redirectToRoute('coreshop_index');
  46.         }
  47.         $form $this->container->get('form.factory')->createNamed(
  48.             'deleteAccount'DeleteAccountType::class
  49.         );
  50.         $form->handleRequest($request);
  51.         if ($form->isSubmitted() && $form->isValid() && $form->get('submit')?->isClicked()) {
  52.             try {
  53.                 $this->container->get('security.token_storage')->setToken(null);
  54.                 $manager->deleteAccount($customer);
  55.                 $request->getSession()->invalidate(0);
  56.                 return $this->redirectToRoute('coreshop_index');
  57.             } catch (Exception $e) {
  58.                 $this->addFlash('error''Hiba történt!');
  59.                 return $this->redirectToRoute('coreshop_index');
  60.             }
  61.         }
  62.         return $this->render($this->templateConfigurator->findTemplate('Customer/delete_account.html'), [
  63.             'customer' => $customer,
  64.             'form' => $form->createView()
  65.         ]);
  66.     }
  67. }