app/Customize/Controller/EntryCustomizeController.php line 38

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Eccube\Entity\BaseInfo;
  4. use Eccube\Entity\Master\CustomerStatus;
  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\Repository\PageRepository;
  12. use Eccube\Service\CartService;
  13. use Eccube\Service\MailService;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpKernel\Exception as HttpException;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  19. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  20. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  21. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  22. use Symfony\Component\Validator\Constraints as Assert;
  23. use Symfony\Component\Validator\Validator\ValidatorInterface;
  24. use Eccube\Controller\EntryController;
  25. class EntryCustomizeController extends EntryController
  26. {
  27.     /**
  28.      * 会員登録画面.
  29.      *
  30.      * @Route("/entry", name="entry", methods={"GET", "POST"})
  31.      * @Route("/entry", name="entry_confirm", methods={"GET", "POST"})
  32.      * @Template("Entry/consent.twig")
  33.      */
  34.     public function index(Request $request)
  35.     {
  36.         if ($this->isGranted('ROLE_USER')) {
  37.             log_info('認証済のためログイン処理をスキップ');
  38.             return $this->redirectToRoute('mypage');
  39.         }
  40.         /** @var $Customer \Eccube\Entity\Customer */
  41.         $Customer $this->customerRepository->newCustomer();
  42.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  43.         $builder $this->formFactory->createBuilder(EntryType::class, $Customer);
  44.         $event = new EventArgs(
  45.             [
  46.                 'builder' => $builder,
  47.                 'Customer' => $Customer,
  48.             ],
  49.             $request
  50.         );
  51.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_INITIALIZE);
  52.         /* @var $form \Symfony\Component\Form\FormInterface */
  53.         $form $builder->getForm();
  54.         
  55.         if ($request->isMethod('POST') && $request->get('mode') === "index") {
  56.             //twigをレンダリングするだけの処理を追加する
  57.             return $this->render(
  58.                 'Entry/index.twig',
  59.                 [
  60.                     'form' => $form->createView(),
  61.                 ]
  62.             );
  63.         }
  64.         $form->handleRequest($request);
  65.         
  66.         if ($form->isSubmitted() && $form->isValid()) {
  67.            
  68.             switch ($request->get('mode')) {
  69.                 case 'confirm':
  70.                     log_info('会員登録確認開始');
  71.                     log_info('会員登録確認完了');
  72.                     return $this->render(
  73.                         'Entry/confirm.twig',
  74.                         [
  75.                             'form' => $form->createView(),
  76.                             'Page' => $this->pageRepository->getPageByRoute('entry_confirm'),
  77.                         ]
  78.                     );
  79.                 case 'complete':
  80.                     log_info('会員登録開始');
  81.                     $encoder $this->encoderFactory->getEncoder($Customer);
  82.                     $salt $encoder->createSalt();
  83.                     $password $encoder->encodePassword($Customer->getPlainPassword(), $salt);
  84.                     $secretKey $this->customerRepository->getUniqueSecretKey();
  85.                     $Customer
  86.                         ->setSalt($salt)
  87.                         ->setPassword($password)
  88.                         ->setSecretKey($secretKey)
  89.                         ->setPoint(0);
  90.                     $this->entityManager->persist($Customer);
  91.                     $this->entityManager->flush();
  92.                     log_info('会員登録完了');
  93.                     $event = new EventArgs(
  94.                         [
  95.                             'form' => $form,
  96.                             'Customer' => $Customer,
  97.                         ],
  98.                         $request
  99.                     );
  100.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_COMPLETE);
  101.                     $activateFlg $this->BaseInfo->isOptionCustomerActivate();
  102.                     // 仮会員設定が有効な場合は、確認メールを送信し完了画面表示.
  103.                     if ($activateFlg) {
  104.                         $activateUrl $this->generateUrl('entry_activate', ['secret_key' => $Customer->getSecretKey()], UrlGeneratorInterface::ABSOLUTE_URL);
  105.                         // メール送信
  106.                         $this->mailService->sendCustomerConfirmMail($Customer$activateUrl);
  107.                         if ($event->hasResponse()) {
  108.                             return $event->getResponse();
  109.                         }
  110.                         log_info('仮会員登録完了画面へリダイレクト');
  111.                         return $this->redirectToRoute('entry_complete');
  112.                     } else {
  113.                         // 仮会員設定が無効な場合は、会員登録を完了させる.
  114.                         $qtyInCart $this->entryActivate($request$Customer->getSecretKey());
  115.                         // URLを変更するため完了画面にリダイレクト
  116.                         return $this->redirectToRoute('entry_activate', [
  117.                             'secret_key' => $Customer->getSecretKey(),
  118.                             'qtyInCart' => $qtyInCart,
  119.                         ]);
  120.                     }
  121.             }
  122.         }
  123.         if ($form->isSubmitted() && !$form->isValid()) {
  124.             //エラーの場合
  125.             return $this->render(
  126.                 'Entry/index.twig',
  127.                 [
  128.                     'form' => $form->createView(),
  129.                 ]
  130.             );
  131.         }
  132.         return [
  133.             'form' => $form->createView(),
  134.         ];
  135.     }
  136.     
  137. }