app/Customize/Controller/EntryController.php line 145

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Customize\Repository\EigyoRepository;
  4. use Customize\Repository\Master\BcRepository;
  5. use Customize\Repository\SibuRepository;
  6. use Customize\Repository\SaibanRepository;
  7. use Customize\Security\Core\Encoder\PasswordEncoder;
  8. use Eccube\Controller\AbstractController;
  9. use Eccube\Entity\BaseInfo;
  10. use Eccube\Entity\Master\CustomerStatus;
  11. use Eccube\Event\EccubeEvents;
  12. use Eccube\Event\EventArgs;
  13. use Eccube\Form\Type\Front\EntryType;
  14. //use Customize\Form\Type\Front\EntryType;
  15. use Eccube\Repository\BaseInfoRepository;
  16. use Eccube\Repository\CustomerRepository;
  17. use Eccube\Repository\Master\CustomerStatusRepository;
  18. use Eccube\Repository\PageRepository;
  19. use Eccube\Service\CartService;
  20. use Eccube\Service\MailService;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  22. use Symfony\Component\Form\FormError;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpKernel\Exception as HttpException;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  27. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  28. use Symfony\Component\Validator\Constraints as Assert;
  29. use Symfony\Component\Validator\Validator\ValidatorInterface;
  30. class EntryController extends AbstractController
  31. {
  32.     /**
  33.      * @var MailService
  34.      */
  35.     protected $mailService;
  36.     /**
  37.      * @var BaseInfo
  38.      */
  39.     protected $BaseInfo;
  40.     /**
  41.      * @var BcRepository
  42.      */
  43.     protected $bcRepository;
  44.     /**
  45.      * @var \Eccube\Service\CartService
  46.      */
  47.     protected $cartService;
  48.     /**
  49.      * @var CustomerRepository
  50.      */
  51.     protected $customerRepository;
  52.     /**
  53.      * @var CustomerStatusRepository
  54.      */
  55.     protected $customerStatusRepository;
  56.     /**
  57.      * @var EigyoRepository
  58.      */
  59.     protected $eigyoRepository;
  60.     /**
  61.      * @var EncoderFactoryInterface
  62.      */
  63.     protected $encoderFactory;
  64.     /**
  65.      * @var PageRepository
  66.      */
  67.     protected $pageRepository;
  68.     /**
  69.      * @var ValidatorInterface
  70.      */
  71.     protected $recursiveValidator;
  72.     /**
  73.      * @var SibuRepository
  74.      */
  75.     protected $sibuRepository;
  76.     /**
  77.      * @var SaibanRepository
  78.      */
  79.     protected $saibanRepository;
  80.     /**
  81.      * EntryController constructor.
  82.      *
  83.      * @param MailService $mailService
  84.      * @param BaseInfoRepository $baseInfoRepository
  85.      * @param CartService $cartService
  86.      * @param CustomerRepository $customerRepository
  87.      * @param CustomerStatusRepository $customerStatusRepository
  88.      * @param EigyoRepository $eigyoRepository
  89.      * @param EncoderFactoryInterface $encoderFactory
  90.      * @param PageRepository $pageRepository
  91.      * @param ValidatorInterface $validatorInterface
  92.      * @param SibuRepository $sibuRepository
  93.      * @param SaibanRepository $saibanRepository
  94.      */
  95.     public function __construct(
  96.         MailService $mailService,
  97.         BaseInfoRepository $baseInfoRepository,
  98.         BcRepository $bcRepository,
  99.         CartService $cartService,
  100.         CustomerRepository $customerRepository,
  101.         CustomerStatusRepository $customerStatusRepository,
  102.         EigyoRepository $eigyoRepository,
  103.         EncoderFactoryInterface $encoderFactory,
  104.         PageRepository $pageRepository,
  105.         ValidatorInterface $validatorInterface,
  106.         SibuRepository $sibuRepository,
  107.         SaibanRepository $saibanRepository
  108.     ) {
  109.         $this->mailService $mailService;
  110.         $this->BaseInfo $baseInfoRepository->get();
  111.         $this->bcRepository $bcRepository;
  112.         $this->cartService $cartService;
  113.         $this->customerRepository $customerRepository;
  114.         $this->customerStatusRepository $customerStatusRepository;
  115.         $this->eigyoRepository $eigyoRepository;
  116.         $this->encoderFactory $encoderFactory;
  117.         $this->pageRepository $pageRepository;
  118.         $this->recursiveValidator $validatorInterface;
  119.         $this->sibuRepository $sibuRepository;
  120.         $this->saibanRepository $saibanRepository;
  121.     }
  122.     /**
  123.      * 会員登録画面.
  124.      *
  125.      * @Route("/entry", name="entry", methods={"GET", "POST"})
  126.      * @Route("/entry", name="entry_confirm", methods={"GET", "POST"})
  127.      * @Template("Entry/index.twig")
  128.      */
  129.     public function index(Request $request)
  130.     {
  131.         if ($this->isGranted('ROLE_USER')) {
  132.             log_info('認証済のためログイン処理をスキップ');
  133.             return $this->redirectToRoute('mypage');
  134.         }
  135.         /** @var $Customer \Eccube\Entity\Customer */
  136.         $Customer $this->customerRepository->newCustomer();
  137.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  138.         $builder $this->formFactory->createBuilder(EntryType::class, $Customer);
  139.         $event = new EventArgs(
  140.             [
  141.                 'builder' => $builder,
  142.                 'Customer' => $Customer,
  143.             ],
  144.             $request
  145.         );
  146.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_INITIALIZE);
  147.         /* @var $form \Symfony\Component\Form\FormInterface */
  148.         $form $builder->getForm();
  149.         /* QRで指定されたキャンペーンコードをセット */
  150.         if (!$form->isSubmitted()) {
  151.             //初期表示なら
  152.             if ($request->getMethod() === 'GET') {
  153.                 //QRのキャンペーンコードをセット
  154.                 if (isset($_GET['campaign_cd'])){
  155.                     //$form->handleRequestは値は変更できない
  156.                     $form->get('campaign_cd10')->setData($_GET['campaign_cd']);
  157.                 }
  158.             }
  159.         }
  160.         $form->handleRequest($request);
  161.         if ($form->isSubmitted() && $form->isValid()) {
  162.             switch ($request->get('mode')) {
  163.                 case 'confirm':
  164.                     log_info('会員登録確認開始');
  165.                     $Eigyo $this->eigyoRepository->getEigyo($Customer->getCampaignCd10());
  166.                     if (is_null($Eigyo)) {
  167.                         $form['campaign_cd10']->addError(new FormError(trans('front.entry.campaign_cd_err')));
  168.                         break;
  169.                     }
  170.                     log_info('会員登録確認完了');
  171.                     return $this->render(
  172.                         'Entry/confirm.twig',
  173.                         [
  174.                             'form' => $form->createView(),
  175.                             'Page' => $this->pageRepository->getPageByRoute('entry_confirm'),
  176.                         ]
  177.                     );
  178.                 case 'complete':
  179.                     log_info('会員登録開始');
  180. //                    $encoder = $this->encoderFactory->getEncoder($Customer);
  181. //                    $salt = $encoder->createSalt();
  182. //                    $password = $encoder->encodePassword($Customer->getPlainPassword(), $salt);
  183.                     $password PasswordEncoder::codeString($Customer->getPlainPassword());
  184.                     $secretKey $this->customerRepository->getUniqueSecretKey();
  185.                     //支部営業所
  186.                     $sibuCd NULL;
  187.                     $eigyoCd NULL;
  188.                     $campaignCd NULL;
  189.                     $this->eigyoRepository->decodeCampaignCd($Customer->getCampaignCd10(), $sibuCd$eigyoCd$campaignCd);
  190.                     $Bc $this->bcRepository->find(5);             // BC区分(BPで登録)
  191.                     $Sibu $this->sibuRepository->find($sibuCd);
  192.                     
  193.                     //新規会員番号取得
  194.                     $hostKono $this->saibanRepository->getNewHostKono();
  195.                     $Customer
  196.                         ->setBc($Bc)
  197.                         ->setInsKbn('4')        // Web登録
  198.                         ->setSibu($Sibu)
  199.                         ->setEigyoCd($eigyoCd)
  200.                         ->setInsSibuCd($sibuCd)
  201.                         ->setInsEigyoCd($eigyoCd)
  202.                         ->setDaibikiYutaiFlg(0)
  203. //                        ->setSalt($salt)
  204.                         ->setPassword($password)
  205.                         ->setSecretKey($secretKey)
  206.                         ->setHostKono($hostKono)
  207.                         ->setPoint(0);
  208.                     $this->entityManager->persist($Customer);
  209.                     $this->entityManager->flush();
  210.                     log_info('会員登録完了');
  211.                     $event = new EventArgs(
  212.                         [
  213.                             'form' => $form,
  214.                             'Customer' => $Customer,
  215.                         ],
  216.                         $request
  217.                     );
  218.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_COMPLETE);
  219.                     $activateFlg $this->BaseInfo->isOptionCustomerActivate();
  220.                     // 仮会員設定が有効な場合は、確認メールを送信し完了画面表示.
  221.                     if ($activateFlg) {
  222.                         $activateUrl $this->generateUrl('entry_activate', ['secret_key' => $Customer->getSecretKey()], UrlGeneratorInterface::ABSOLUTE_URL);
  223.                         // メール送信
  224.                         $this->mailService->sendCustomerConfirmMail($Customer$activateUrl);
  225.                         if ($event->hasResponse()) {
  226.                             return $event->getResponse();
  227.                         }
  228.                         log_info('仮会員登録完了画面へリダイレクト');
  229.                         return $this->redirectToRoute('entry_complete');
  230.                     } else {
  231.                         // 仮会員設定が無効な場合は、会員登録を完了させる.
  232.                         $qtyInCart $this->entryActivate($request$Customer->getSecretKey());
  233.                         // URLを変更するため完了画面にリダイレクト
  234.                         return $this->redirectToRoute('entry_activate', [
  235.                             'secret_key' => $Customer->getSecretKey(),
  236.                             'qtyInCart' => $qtyInCart,
  237.                         ]);
  238.                     }
  239.             }
  240.         }
  241.         return [
  242.             'form' => $form->createView(),
  243.         ];
  244.     }
  245.     /**
  246.      * 会員のアクティベート(本会員化)を行う.
  247.      *
  248.      * @Route("/entry/activate/{secret_key}/{qtyInCart}", name="entry_activate", methods={"GET"})
  249.      * @Template("Entry/activate.twig")
  250.      */
  251.     public function activate(Request $request$secret_key$qtyInCart null)
  252.     {
  253.         $errors $this->recursiveValidator->validate(
  254.             $secret_key,
  255.             [
  256.                 new Assert\NotBlank(),
  257.                 new Assert\Regex(
  258.                     [
  259.                         'pattern' => '/^[a-zA-Z0-9]+$/',
  260.                     ]
  261.                 ),
  262.             ]
  263.         );
  264.         if (!$this->session->has('eccube.login.target.path')) {
  265.             $this->setLoginTargetPath($this->generateUrl('mypage', [], UrlGeneratorInterface::ABSOLUTE_URL));
  266.         }
  267.         if (!is_null($qtyInCart)) {
  268.             return [
  269.                 'qtyInCart' => $qtyInCart,
  270.             ];
  271.         } elseif ($request->getMethod() === 'GET' && count($errors) === 0) {
  272.             // 会員登録処理を行う
  273.             $qtyInCart $this->entryActivate($request$secret_key);
  274.             return [
  275.                 'qtyInCart' => $qtyInCart,
  276.             ];
  277.         }
  278.         throw new HttpException\NotFoundHttpException();
  279.     }
  280.     /**
  281.      * 会員登録処理を行う
  282.      *
  283.      * @param Request $request
  284.      * @param $secret_key
  285.      *
  286.      * @return \Eccube\Entity\Cart|mixed
  287.      */
  288.     private function entryActivate(Request $request$secret_key)
  289.     {
  290.         log_info('本会員登録開始');
  291.         $Customer $this->customerRepository->getProvisionalCustomerBySecretKey($secret_key);
  292.         if (is_null($Customer)) {
  293.             throw new HttpException\NotFoundHttpException();
  294.         }
  295.         $CustomerStatus $this->customerStatusRepository->find(CustomerStatus::REGULAR);
  296. //        $Customer->setStatus($CustomerStatus);
  297.         $Customer->setStatus($CustomerStatus)
  298.                  ->setUpdateDate(new \DateTime())
  299.                  ->setHonTorokuDate(new \DateTime())
  300.                  ->setDlKbn('1');
  301.         $this->entityManager->persist($Customer);
  302.         $this->entityManager->flush();
  303.         log_info('本会員登録完了');
  304.         $event = new EventArgs(
  305.             [
  306.                 'Customer' => $Customer,
  307.             ],
  308.             $request
  309.         );
  310.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE);
  311.         // メール送信
  312.         $this->mailService->sendCustomerCompleteMail($Customer);
  313.         // Assign session carts into customer carts
  314.         $Carts $this->cartService->getCarts();
  315.         $qtyInCart 0;
  316.         foreach ($Carts as $Cart) {
  317.             $qtyInCart += $Cart->getTotalQuantity();
  318.         }
  319.         if ($qtyInCart) {
  320.             $this->cartService->save();
  321.         }
  322.         return $qtyInCart;
  323.     }
  324. }