app/Customize/Controller/EntryController.php line 82

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Eccube\Controller\EntryController as ControllerEntryController;
  4. use Eccube\Entity\Customer;
  5. use Eccube\Event\EccubeEvents;
  6. use Eccube\Event\EventArgs;
  7. use Eccube\Form\Type\Front\EntryType;
  8. use Eccube\Repository\BaseInfoRepository;
  9. use Eccube\Repository\CustomerRepository;
  10. use Eccube\Repository\Master\CustomerStatusRepository;
  11. use Eccube\Service\CartService;
  12. use Eccube\Service\MailService;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  16. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  17. use Symfony\Component\Validator\Validator\ValidatorInterface;
  18. use Eccube\Repository\PageRepository;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  20. use Symfony\Component\DependencyInjection\ContainerInterface;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  23. class EntryController extends ControllerEntryController{
  24.     
  25.     /** @var string */
  26.     protected $photoDir;
  27.     /** @var string */
  28.     protected $tempDir;
  29.     /**
  30.      * EntryController constructor.
  31.      * @param CartService $cartService
  32.      * @param CustomerStatusRepository $customerStatusRepository
  33.      * @param MailService $mailService
  34.      * @param BaseInfoRepository $baseInfoRepository
  35.      * @param CustomerRepository $customerRepository
  36.      * @param EncoderFactoryInterface $encoderFactory
  37.      * @param ValidatorInterface $validatorInterface
  38.      * @param TokenStorageInterface $tokenStorage
  39.      */
  40.     public function __construct(
  41.         CartService $cartService,
  42.         CustomerStatusRepository $customerStatusRepository,
  43.         MailService $mailService,
  44.         BaseInfoRepository $baseInfoRepository,
  45.         CustomerRepository $customerRepository,
  46.         EncoderFactoryInterface $encoderFactory,
  47.         ValidatorInterface $validatorInterface,
  48.         TokenStorageInterface $tokenStorage,
  49.         PageRepository $pageRepository,
  50.         ContainerInterface $container
  51.     ) {
  52.         parent::__construct(
  53.             $cartService,
  54.             $customerStatusRepository,
  55.             $mailService,
  56.             $baseInfoRepository,
  57.             $customerRepository,
  58.             $encoderFactory,
  59.             $validatorInterface,
  60.             $tokenStorage,
  61.             $pageRepository
  62.         );
  63.         $projectDir $container->getParameter('kernel.project_dir');
  64.         $this->photoDir $projectDir '/html/upload/customer_photo';
  65.         $this->tempDir $projectDir '/html/upload/temp';
  66.     }
  67.     
  68.     /**
  69.      * 会員登録画面.
  70.      *
  71.      * @Route("/entry", name="entry", methods={"GET", "POST"})
  72.      * @Route("/entry", name="entry_confirm", methods={"GET", "POST"})
  73.      * @Template("Entry/index.twig")
  74.      */
  75.     public function index(Request $request)
  76.     {
  77.         if ($this->isGranted('ROLE_USER')) {
  78.             log_info('認証済のためログイン処理をスキップ');
  79.             return $this->redirectToRoute('mypage');
  80.         }
  81.         /** @var Customer $Customer */
  82.         $Customer $this->customerRepository->newCustomer();
  83.         $builder $this->formFactory->createBuilder(EntryType::class, $Customer);
  84.         $event = new EventArgs(
  85.             [
  86.                 'builder' => $builder,
  87.                 'Customer' => $Customer,
  88.             ],
  89.             $request
  90.         );
  91.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_INITIALIZE);
  92.         $form $builder->getForm();
  93.         $form->handleRequest($request);
  94.         if ($form->isSubmitted() && $form->isValid()) {
  95.             switch ($request->get('mode')) {
  96.                 case 'confirm':
  97.                     log_info('会員登録確認開始');
  98.                     // 写真の一時保存処理
  99.                     $photo $form['photo']->getData();
  100.                     if ($photo instanceof UploadedFile) {
  101.                         $fileName md5(uniqid()).'.'.$photo->getClientOriginalExtension();
  102.                         $photo->move($this->tempDir$fileName);
  103.                         $Customer->setPhoto($fileName);
  104.                         $this->session->set('eccube.front.customer.photo'$fileName);
  105.                     }
  106.                     log_info('会員登録確認完了');
  107.                     return $this->render(
  108.                         'Entry/confirm.twig',
  109.                         [
  110.                             'form' => $form->createView(),
  111.                             'Page' => $this->pageRepository->getPageByRoute('entry_confirm'),
  112.                         ]
  113.                     );
  114.                 case 'complete':
  115.                     log_info('会員登録開始');
  116.                     $encoder $this->encoderFactory->getEncoder($Customer);
  117.                     $salt $encoder->createSalt();
  118.                     $password $encoder->encodePassword($Customer->getPlainPassword(), $salt);
  119.                     $secretKey $this->customerRepository->getUniqueSecretKey();
  120.                     $Customer
  121.                         ->setSalt($salt)
  122.                         ->setPassword($password)
  123.                         ->setSecretKey($secretKey)
  124.                         ->setPoint(0);
  125.                     // 写真の本保存処理
  126.                     $photoName $this->session->get('eccube.front.customer.photo');
  127.                     if ($photoName && file_exists($this->tempDir.'/'.$photoName)) {
  128.                         rename(
  129.                             $this->tempDir.'/'.$photoName,
  130.                             $this->photoDir.'/'.$photoName
  131.                         );
  132.                         $Customer->setPhoto($photoName);
  133.                     }
  134.                     $this->entityManager->persist($Customer);
  135.                     $this->entityManager->flush();
  136.                     log_info('会員登録完了');
  137.                     $event = new EventArgs(
  138.                         [
  139.                             'form' => $form,
  140.                             'Customer' => $Customer,
  141.                         ],
  142.                         $request
  143.                     );
  144.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_COMPLETE);
  145.                     $activateFlg $this->BaseInfo->isOptionCustomerActivate();
  146.                     if ($activateFlg) {
  147.                         $activateUrl $this->generateUrl('entry_activate', ['secret_key' => $Customer->getSecretKey()], UrlGeneratorInterface::ABSOLUTE_URL);
  148.                         $this->mailService->sendCustomerConfirmMail($Customer$activateUrl);
  149.                         if ($event->hasResponse()) {
  150.                             return $event->getResponse();
  151.                         }
  152.                         log_info('仮会員登録完了画面へリダイレクト');
  153.                         return $this->redirectToRoute('entry_complete');
  154.                     } else {
  155.                         $qtyInCart $this->entryActivate($request$Customer->getSecretKey());
  156.                         return $this->redirectToRoute('entry_activate', [
  157.                             'secret_key' => $Customer->getSecretKey(),
  158.                             'qtyInCart' => $qtyInCart,
  159.                         ]);
  160.                     }
  161.             }
  162.         }
  163.         return [
  164.             'form' => $form->createView(),
  165.         ];
  166.     }
  167. }