app/Customize/Controller/UpdateCustomerController.php line 164

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Doctrine\ORM\EntityManager;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Eccube\Common\EccubeConfig;
  10. use Eccube\Repository\PluginRepository;
  11. use Eccube\Service\Composer\ComposerServiceInterface;
  12. use Eccube\Util\CacheUtil;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use Eccube\Service\EntityProxyService;
  15. use Eccube\Service\SchemaService;
  16. use Eccube\Service\PluginApiService;
  17. use Eccube\Service\SystemService;
  18. use Eccube\Service\PluginContext;
  19. use Eccube\Util\StringUtil;
  20. //use Symfony\Bridge\Doctrine\RegistryInterface;
  21. use Doctrine\Common\Persistence\ManagerRegistry;
  22. use Eccube\Entity\Master\CustomerStatus;
  23. use Eccube\Repository\Master\CustomerStatusRepository;
  24. use Eccube\Repository\CustomerRepository;
  25. class UpdateCustomerController
  26. {
  27.     /**
  28.      * @var EccubeConfig
  29.      */
  30.     protected $eccubeConfig;
  31.     /**
  32.      * @var EntityManager
  33.      */
  34.     protected $entityManager;
  35.     /**
  36.      * @var PluginRepository
  37.      */
  38.     protected $pluginRepository;
  39.     /**
  40.      * @var EntityProxyService
  41.      */
  42.     protected $entityProxyService;
  43.     /**
  44.      * @var SchemaService
  45.      */
  46.     protected $schemaService;
  47.     /**
  48.      * @var ComposerServiceInterface
  49.      */
  50.     protected $composerService;
  51.     const VENDOR_NAME 'ec-cube';
  52.     /**
  53.      * Plugin type/library of ec-cube
  54.      */
  55.     const ECCUBE_LIBRARY 1;
  56.     /**
  57.      * Plugin type/library of other (except ec-cube)
  58.      */
  59.     const OTHER_LIBRARY 2;
  60.     /**
  61.      * @var string %kernel.project_dir%
  62.      */
  63.     private $projectRoot;
  64.     /**
  65.      * @var string %kernel.environment%
  66.      */
  67.     private $environment;
  68.     /**
  69.      * @var ContainerInterface
  70.      */
  71.     protected $container;
  72.     /** @var CacheUtil */
  73.     protected $cacheUtil;
  74.     /**
  75.      * @var PluginApiService
  76.      */
  77.     private $pluginApiService;
  78.     /**
  79.      * @var SystemService
  80.      */
  81.     private $systemService;
  82.     /**
  83.      * @var PluginContext
  84.      */
  85.     private $pluginContext;
  86.     /**
  87.      * @var CustomerRepository
  88.      */
  89.     protected $customerRepository;
  90.     /**
  91.      * PluginService constructor.
  92.      *
  93.      * @param EntityManagerInterface $entityManager
  94.      * @param PluginRepository $pluginRepository
  95.      * @param EntityProxyService $entityProxyService
  96.      * @param SchemaService $schemaService
  97.      * @param EccubeConfig $eccubeConfig
  98.      * @param ContainerInterface $container
  99.      * @param CacheUtil $cacheUtil
  100.      * @param ComposerServiceInterface $composerService
  101.      * @param PluginApiService $pluginApiService
  102.      * @param SystemService $systemService
  103.      * @param PluginContext $pluginContext
  104.      * @param RegistryInterface $registry
  105.      * 
  106.      */
  107.     public function __construct(
  108.         EntityManagerInterface $entityManager,
  109.         PluginRepository $pluginRepository,
  110.         EntityProxyService $entityProxyService,
  111.         SchemaService $schemaService,
  112.         EccubeConfig $eccubeConfig,
  113.         ContainerInterface $container,
  114.         CacheUtil $cacheUtil,
  115.         ComposerServiceInterface $composerService,
  116.         PluginApiService $pluginApiService,
  117.         SystemService $systemService,
  118.         PluginContext $pluginContext,
  119.         CustomerRepository $customerRepository
  120.         //RegistryInterface $registry
  121.         // ManagerRegistry $registry
  122.         ) {
  123.         // parent::__construct($registry, Customer::class);
  124.         $this->entityManager $entityManager;
  125.         $this->pluginRepository $pluginRepository;
  126.         $this->entityProxyService $entityProxyService;
  127.         $this->schemaService $schemaService;
  128.         $this->eccubeConfig $eccubeConfig;
  129.         $this->projectRoot $eccubeConfig->get('kernel.project_dir');
  130.         $this->environment $eccubeConfig->get('kernel.environment');
  131.         $this->container $container;
  132.         $this->cacheUtil $cacheUtil;
  133.         $this->composerService $composerService;
  134.         $this->pluginApiService $pluginApiService;
  135.         $this->systemService $systemService;
  136.         $this->pluginContext $pluginContext;
  137.         $this->customerRepository $customerRepository;
  138.     }
  139.     /**
  140.      * @Route("/api/update")
  141.      * @Method("POST")
  142.     */
  143.     public function getAction(Request $request)
  144.     {
  145.         $ip getenv('API_KV_IP');
  146.         // $ip = "3.114.86.82";
  147.         // $clientip = $request->getClientIp();
  148.         // $ips = explode (".",$ip);
  149.         // $clientips = explode (".",$clientip);
  150.         // log_info('会員編集API ', ['HTTP_X_FORWARDED_FOR' => $_SERVER['HTTP_X_FORWARDED_FOR']]);
  151.         // log_info('会員編集API ', ['IP' => $ips,'IP2' => $clientips]);
  152.         // log_info('会員編集API ', ['IP' => $ips[0],'IP2' => $clientips[0]]);
  153.         // log_info('会員編集API ', ['is not *' => ($ips[0] !== '*')]);
  154.         // if($ips[0] !== "*"){
  155.         //     if($ips[0] != $clientips[0]){
  156.         //         log_info('会員編集API IPエラー1', ['IP' => $request->getClientIp()]);
  157.         //         $return_code['status'] = false;
  158.         //         $return_code['error_message'] = 'IPエラー1';
  159.         //         return new Response(json_encode($return_code));
  160.         //     }
  161.         // }
  162.         // if($ips[1] !== "*"){
  163.         //     if($ips[1] != $clientips[1]){
  164.         //         log_info('会員編集API IPエラー2', ['IP' => $request->getClientIp()]);
  165.         //         $return_code['status'] = false;
  166.         //         $return_code['error_message'] = 'IPエラー2';
  167.         //         return new Response(json_encode($return_code));
  168.         //     }
  169.         // }
  170.         // if($ips[2] !== "*"){
  171.         //     if($ips[2] != $clientips[2]){
  172.         //         log_info('会員編集API IPエラー3', ['IP' => $request->getClientIp()]);
  173.         //         $return_code['status'] = false;
  174.         //         $return_code['error_message'] = 'IPエラー3';
  175.         //         return new Response(json_encode($return_code));
  176.         //     }
  177.         // }
  178.         // if($ips[3] !== "*"){
  179.         //     if($ips[3] != $clientips[3]){
  180.         //         log_info('会員編集API IPエラー4', ['IP' => $request->getClientIp()]);
  181.         //         $return_code['status'] = false;
  182.         //         $return_code['error_message'] = 'IPエラー4';
  183.         //         return new Response(json_encode($return_code));
  184.         //     }
  185.         // }
  186.         // if ($_SERVER['HTTP_X_FORWARDED_FOR'] != $ip) {
  187.         if ($_SERVER['HTTP_X_FORWARDED_FOR'] != $ip) {
  188.             log_info('会員編集API IPエラー', ['IP' => $_SERVER['HTTP_X_FORWARDED_FOR']]);
  189.             $return_code['status'] = false;
  190.             $return_code['error_message'] = 'IPエラー';
  191.             return new Response(json_encode($return_code));
  192.         }
  193.         $content $request->getContent();
  194.         $param json_decode($contenttrue);
  195.         $em $this->entityManager;
  196.         try{
  197.             $aes_key getenv('API_AES_KEY');
  198.             log_info('会員編集API ', ['id' => $param["user_id"],'mail' => $param['mail_address'],'pass' => $param['password'],'salt' => $param['salt']]);
  199.             if(!empty($param['mail_address']) && !empty($param['user_id']) && !empty($param['password']) && !empty($param['salt'])){
  200.                 $mail_address openssl_decrypt($param["mail_address"],'aes-256-ecb',$aes_key);
  201.                 $user_id openssl_decrypt($param["user_id"],'aes-256-ecb',$aes_key);
  202.                 $password $param["password"];
  203.                 $salt $param["salt"];
  204.             }else{
  205.                 $return_code['status'] = false;
  206.                 $return_code['user_id'] = '';
  207.                 $return_code['error_no'] = 4;
  208.                 $return_code['message'] = '会員編集エラー()';
  209.                 return new Response(json_encode($return_code));
  210.             }
  211.             log_info('会員編集API ', ['id' => $user_id,'mail' => $mail_address,'pass' => $password,'salt' => $salt]);
  212.             $em->getConnection()->beginTransaction();
  213.             $secret_Key $this->customerRepository->getUniqueSecretKey();
  214.             // $secretkey = $this->getUniqueSecretKey();
  215.             $conn $em->getConnection();
  216.             // 存在チェック
  217.             // $stmt = $conn->prepare('SELECT id FROM dtb_customer WHERE id = :id;');
  218.             // $stmt->execute([':id' => $user_id]);
  219.             // $row = $stmt->fetch();
  220.             $row $this->customerRepository->findOneBy([
  221.                 'id' => $user_id,
  222.             ]);
  223.             if (!$row) {
  224.                 $return_code['status'] = false;
  225.                 $return_code['user_id'] = $param["user_id"];
  226.                 $return_code['error_message'] = '会員は登録されていません。';
  227.                 return new Response(json_encode($return_code));
  228.             }
  229.             $sth $conn->prepare('UPDATE dtb_customer set email = :email, password = :password, salt = :salt, update_date = current_timestamp WHERE id = :id;');
  230.             $sth->execute([
  231.                 ':email' => $mail_address,
  232.                 ':password' => $password,
  233.                 ':salt' => $salt,
  234.                 ':id' => $user_id
  235.             ]);
  236.             $em->getConnection()->commit();
  237.             
  238.             $return_code['status'] = true;
  239.             $return_code['user_id'] = $param["user_id"];
  240.             $return_code['error_message'] = '';
  241.         } catch (\Exception $e) {
  242.             $return_code['status'] = false;
  243.             $return_code['user_id'] = '';
  244.             $return_code['error_message'] = '会員編集エラー('.$e.')';
  245.             $conn->rollback();
  246.         }
  247.         return new Response(json_encode($return_code));
  248.     }
  249.     /**
  250.      * ユニークなシークレットキーを返す.
  251.      *
  252.      * @return string
  253.      */
  254.     // public function getUniqueSecretKey()
  255.     // {
  256.     //     $em2 = $this->entityManager;
  257.     //     $conn2 = $em2->getConnection();
  258.     //     do {
  259.     //         $key = StringUtil::random(32);
  260.     //         $stmt2 = $conn2->prepare('SELECT id FROM dtb_customer WHERE secret_key = :secretkey;');
  261.     //         $stmt2->execute([':secretkey' => $key]);
  262.     //         $Customer = $stmt2->fetch();
  263.     //     } while ($Customer);
  264.     //     return $key;
  265.     // }
  266. }