app/Customize/Controller/MypageController.php line 103

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Controller;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Entity\BaseInfo;
  15. use Eccube\Entity\Customer;
  16. use Eccube\Entity\Product;
  17. use Eccube\Entity\Order;
  18. use Eccube\Event\EccubeEvents;
  19. use Eccube\Event\EventArgs;
  20. use Eccube\Exception\CartException;
  21. use Eccube\Form\Type\Front\CustomerLoginType;
  22. use Eccube\Repository\BaseInfoRepository;
  23. use Eccube\Repository\CustomerFavoriteProductRepository;
  24. use Eccube\Repository\OrderRepository;
  25. use Eccube\Repository\ProductRepository;
  26. use Eccube\Service\CartService;
  27. use Eccube\Service\PurchaseFlow\PurchaseContext;
  28. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  29. use Knp\Component\Pager\Paginator;
  30. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  33. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  34. use Symfony\Component\Routing\Annotation\Route;
  35. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  36. use Symfony\Component\HttpFoundation\Cookie;
  37. use Symfony\Component\HttpFoundation\Response;
  38. class MypageController extends AbstractController
  39. {
  40.     /**
  41.      * @var ProductRepository
  42.      */
  43.     protected $productRepository;
  44.     /**
  45.      * @var CustomerFavoriteProductRepository
  46.      */
  47.     protected $customerFavoriteProductRepository;
  48.     /**
  49.      * @var BaseInfo
  50.      */
  51.     protected $BaseInfo;
  52.     /**
  53.      * @var CartService
  54.      */
  55.     protected $cartService;
  56.     /**
  57.      * @var OrderRepository
  58.      */
  59.     protected $orderRepository;
  60.     /**
  61.      * @var PurchaseFlow
  62.      */
  63.     protected $purchaseFlow;
  64.     /**
  65.      * MypageController constructor.
  66.      *
  67.      * @param OrderRepository $orderRepository
  68.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  69.      * @param CartService $cartService
  70.      * @param BaseInfoRepository $baseInfoRepository
  71.      * @param PurchaseFlow $purchaseFlow
  72.      */
  73.     public function __construct(
  74.         OrderRepository $orderRepository,
  75.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  76.         CartService $cartService,
  77.         BaseInfoRepository $baseInfoRepository,
  78.         PurchaseFlow $purchaseFlow
  79.     ) {
  80.         $this->orderRepository $orderRepository;
  81.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  82.         $this->BaseInfo $baseInfoRepository->get();
  83.         $this->cartService $cartService;
  84.         $this->purchaseFlow $purchaseFlow;
  85.     }
  86.     /**
  87.      * ログイン画面.
  88.      *
  89.      * @Route("/mypage/login", name="mypage_login")
  90.      * @Template("Mypage/login.twig")
  91.      */
  92.     public function login(Request $requestAuthenticationUtils $utils)
  93.     {
  94.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
  95.             log_info('認証済のためログイン処理をスキップ');
  96.             return $this->redirectToRoute('mypage');
  97.         }
  98.         // カスタマイズ:GET 'redir' が渡されたら、変数にいれる
  99.         // ログイン後にページ遷移させる
  100.         if($request->query->get('redir')) {
  101.             $request->cookies->set('redir'$request->query->get('redir'));
  102.         }
  103.         /* @var $form \Symfony\Component\Form\FormInterface */
  104.         $builder $this->formFactory
  105.             ->createNamedBuilder(''CustomerLoginType::class);
  106.         $builder->get('login_memory')->setData((bool) $request->getSession()->get('_security.login_memory'));
  107.         if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  108.             $Customer $this->getUser();
  109.             if ($Customer instanceof Customer) {
  110.                 $builder->get('login_email')
  111.                     ->setData($Customer->getEmail());
  112.             }
  113.         }
  114.         $event = new EventArgs(
  115.             [
  116.                 'builder' => $builder,
  117.             ],
  118.             $request
  119.         );
  120.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE$event);
  121.         $form $builder->getForm();
  122.         return [
  123.             'error' => $utils->getLastAuthenticationError(),
  124.             'form' => $form->createView(),
  125.             'redir' => $request->cookies->get('redir'),
  126.         ];
  127.     }
  128. }