<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller;
use Eccube\Controller\AbstractController;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Customer;
use Eccube\Entity\Product;
use Eccube\Entity\Order;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Exception\CartException;
use Eccube\Form\Type\Front\CustomerLoginType;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\CustomerFavoriteProductRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Repository\ProductRepository;
use Eccube\Service\CartService;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Knp\Component\Pager\Paginator;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
class MypageController extends AbstractController
{
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @var CustomerFavoriteProductRepository
*/
protected $customerFavoriteProductRepository;
/**
* @var BaseInfo
*/
protected $BaseInfo;
/**
* @var CartService
*/
protected $cartService;
/**
* @var OrderRepository
*/
protected $orderRepository;
/**
* @var PurchaseFlow
*/
protected $purchaseFlow;
/**
* MypageController constructor.
*
* @param OrderRepository $orderRepository
* @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
* @param CartService $cartService
* @param BaseInfoRepository $baseInfoRepository
* @param PurchaseFlow $purchaseFlow
*/
public function __construct(
OrderRepository $orderRepository,
CustomerFavoriteProductRepository $customerFavoriteProductRepository,
CartService $cartService,
BaseInfoRepository $baseInfoRepository,
PurchaseFlow $purchaseFlow
) {
$this->orderRepository = $orderRepository;
$this->customerFavoriteProductRepository = $customerFavoriteProductRepository;
$this->BaseInfo = $baseInfoRepository->get();
$this->cartService = $cartService;
$this->purchaseFlow = $purchaseFlow;
}
/**
* ログイン画面.
*
* @Route("/mypage/login", name="mypage_login")
* @Template("Mypage/login.twig")
*/
public function login(Request $request, AuthenticationUtils $utils)
{
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
log_info('認証済のためログイン処理をスキップ');
return $this->redirectToRoute('mypage');
}
// カスタマイズ:GET 'redir' が渡されたら、変数にいれる
// ログイン後にページ遷移させる
if($request->query->get('redir')) {
$request->cookies->set('redir', $request->query->get('redir'));
}
/* @var $form \Symfony\Component\Form\FormInterface */
$builder = $this->formFactory
->createNamedBuilder('', CustomerLoginType::class);
$builder->get('login_memory')->setData((bool) $request->getSession()->get('_security.login_memory'));
if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$Customer = $this->getUser();
if ($Customer instanceof Customer) {
$builder->get('login_email')
->setData($Customer->getEmail());
}
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE, $event);
$form = $builder->getForm();
return [
'error' => $utils->getLastAuthenticationError(),
'form' => $form->createView(),
'redir' => $request->cookies->get('redir'),
];
}
}