src/Eccube/Controller/Mypage/ChangeController.php line 62

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 Eccube\Controller\Mypage;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Entity\Customer;
  15. use Eccube\Event\EccubeEvents;
  16. use Eccube\Event\EventArgs;
  17. use Eccube\Form\Type\Front\EntryType;
  18. use Eccube\Repository\CustomerRepository;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
  23. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  24. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  25. class ChangeController extends AbstractController
  26. {
  27.     /**
  28.      * @var TokenStorage
  29.      */
  30.     protected $tokenStorage;
  31.     /**
  32.      * @var CustomerRepository
  33.      */
  34.     protected $customerRepository;
  35.     /**
  36.      * @var EncoderFactoryInterface
  37.      */
  38.     protected $encoderFactory;
  39.     public function __construct(
  40.         CustomerRepository $customerRepository,
  41.         EncoderFactoryInterface $encoderFactory,
  42.         TokenStorageInterface $tokenStorage
  43.     ) {
  44.         $this->customerRepository $customerRepository;
  45.         $this->encoderFactory $encoderFactory;
  46.         $this->tokenStorage $tokenStorage;
  47.     }
  48.     /**
  49.      * 会員情報編集画面.
  50.      *
  51.      * @Route("/mypage/change", name="mypage_change", methods={"GET", "POST"})
  52.      * @Template("Mypage/change.twig")
  53.      */
  54.     public function index(Request $request)
  55.     {
  56.         /** @var Customer $Customer */
  57.         $Customer $this->getUser();
  58.         $Customer->setPlainPassword($this->eccubeConfig['eccube_default_password']);
  59.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  60.         $builder $this->formFactory->createBuilder(EntryType::class, $Customer);
  61.         $event = new EventArgs(
  62.             [
  63.                 'builder' => $builder,
  64.                 'Customer' => $Customer,
  65.             ],
  66.             $request
  67.         );
  68.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_CHANGE_INDEX_INITIALIZE);
  69.         /* @var $form \Symfony\Component\Form\FormInterface */
  70.         $form $builder->getForm();
  71.         $form->handleRequest($request);
  72.         if ($form->isSubmitted() && $form->isValid()) {
  73.             log_info('会員編集開始');
  74.             if ($Customer->getPlainPassword() !== $this->eccubeConfig['eccube_default_password']) {
  75.                 $encoder $this->encoderFactory->getEncoder($Customer);
  76.                 if ($Customer->getSalt() === null) {
  77.                     $Customer->setSalt($encoder->createSalt());
  78.                 }
  79.                 $Customer->setPassword(
  80.                     $encoder->encodePassword($Customer->getPlainPassword(), $Customer->getSalt())
  81.                 );
  82.             }
  83.             $this->entityManager->flush();
  84.             log_info('会員編集完了');
  85.             $event = new EventArgs(
  86.                 [
  87.                     'form' => $form,
  88.                     'Customer' => $Customer,
  89.                 ],
  90.                 $request
  91.             );
  92.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_CHANGE_INDEX_COMPLETE);
  93.             return $this->redirect($this->generateUrl('mypage_change_complete'));
  94.         }
  95.         return [
  96.             'form' => $form->createView(),
  97.         ];
  98.     }
  99.     /**
  100.      * 会員情報編集完了画面.
  101.      *
  102.      * @Route("/mypage/change_complete", name="mypage_change_complete", methods={"GET"})
  103.      * @Template("Mypage/change_complete.twig")
  104.      */
  105.     public function complete(Request $request)
  106.     {
  107.         return [];
  108.     }
  109. }