app/Customize/Controller/CustomTopController.php line 192

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 Customize\Controller;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  16. use Symfony\Component\HttpFoundation\Request;
  17. //require 'vendor/autoload.php';
  18. use GuzzleHttp\Client;
  19. use Eccube\Repository\CustomerRepository;
  20. use Eccube\Repository\Master\CustomerStatusRepository;
  21. use Eccube\Service\MailService;
  22. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  23. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  24. use Symfony\Component\Validator\Validator\ValidatorInterface;
  25. use Eccube\Service\CartService;
  26. use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
  27. use Symfony\Component\HttpFoundation\Cookie;
  28. class CustomTopController extends AbstractController
  29. {
  30.         private $client;
  31.     
  32.     /**
  33.      * @var CustomerStatusRepository
  34.      */
  35.     protected $customerStatusRepository;
  36.     /**
  37.      * @var ValidatorInterface
  38.      */
  39.     protected $recursiveValidator;
  40.     /**
  41.      * @var MailService
  42.      */
  43.     protected $mailService;
  44.     /**
  45.      * @var CustomerRepository
  46.      */
  47.     protected $customerRepository;
  48.     /**
  49.      * @var EncoderFactoryInterface
  50.      */
  51.     protected $encoderFactory;
  52.     /**
  53.      * @var TokenStorageInterface
  54.      */
  55.     protected $tokenStorage;
  56.     /**
  57.      * @var \Eccube\Service\CartService
  58.      */
  59.     protected $cartService;
  60.     private $authenticationManager;
  61.     /**
  62.      * EntryController constructor.
  63.      *
  64.      * @param CartService $cartService
  65.      * @param CustomerStatusRepository $customerStatusRepository
  66.      * @param MailService $mailService
  67.      * @param CustomerRepository $customerRepository
  68.      * @param EncoderFactoryInterface $encoderFactory
  69.      * @param ValidatorInterface $validatorInterface
  70.      * @param TokenStorageInterface $tokenStorage
  71.      * @param AuthenticationManagerInterface $authenticationManager An AuthenticationManager instance
  72.      */
  73.     public function __construct(
  74.         CartService $cartService,
  75.         CustomerStatusRepository $customerStatusRepository,
  76.         MailService $mailService,
  77.         CustomerRepository $customerRepository,
  78.         EncoderFactoryInterface $encoderFactory,
  79.         ValidatorInterface $validatorInterface,
  80.         TokenStorageInterface $tokenStorage,
  81.         AuthenticationManagerInterface $authenticationManager
  82.     ) {
  83.         $this->customerStatusRepository $customerStatusRepository;
  84.         $this->mailService $mailService;
  85.         $this->customerRepository $customerRepository;
  86.         $this->encoderFactory $encoderFactory;
  87.         $this->recursiveValidator $validatorInterface;
  88.         $this->tokenStorage $tokenStorage;
  89.         $this->cartService $cartService;
  90.         $this->authenticationManager $authenticationManager;
  91.     }
  92.         // public function __construct(HttpClientInterface $client)
  93.         // {
  94.         //     $this->client = $client;
  95.         // }
  96.     /**
  97.      * @Route("/", name="homepage")
  98.      * @Template("index.twig")
  99.      * Unirest\Request::get($url, $headers = array(), $parameters = null)
  100.      * Unirest\Request::post($url, $headers = array(), $body = null)
  101.      * Unirest\Request::put($url, $headers = array(), $body = null)
  102.      * Unirest\Request::patch($url, $headers = array(), $body = null)
  103.      * Unirest\Request::delete($url, $headers = array(), $body = null)
  104.      */
  105.     public function index(Request $request)
  106.     {
  107.         // $Customer = $this->getUser();
  108.         $token $this->tokenStorage->getToken();
  109.         log_info('ログイン確認 ',["token" => $token]);
  110.         if(is_null($token)){
  111.             $Customer $this->getUser();
  112.         }else{
  113.             $Customer $token->getUser();
  114.         }
  115.         log_info('ログイン確認 ',["id" => $Customer]);
  116.         if(!$Customer){
  117.             if(isset($_COOKIE["nooVAJhmuvazsDiDliP"])){
  118.                 $user_id =  $_COOKIE["nooVAJhmuvazsDiDliP"];
  119.                 $client = new Client();
  120.                 $options = [
  121.                     'headers' => [
  122.                         'Content-Type' => 'application/x-www-form-urlencoded'],
  123.                     'form_params' => [
  124.                         "site_id" => 1,
  125.                         "user_id" => $user_id
  126.                        ]
  127.                 ];
  128.                 $url getenv('API_KV_REGIST');
  129.                 $response $client->request('POST'$url$options);
  130.                 $res json_decode($response->getBody());
  131.                 if($res->status){
  132.                     $options = [
  133.                         'headers' => [
  134.                             'Content-Type' => 'application/x-www-form-urlencoded'],
  135.                         'form_params' => [
  136.                             "site_id" => 1,
  137.                             "user_id" => $user_id,
  138.                             "password" => $res->password
  139.                         ]
  140.                     ];
  141.                     $url getenv('API_KV_LOGIN');
  142.                     $response $client->request('POST'$url$options);
  143.                     $res json_decode($response->getBody());
  144.                     if($res->status){
  145.                         log_info('ログイン後処理1');
  146.                         $Carts $this->cartService->getCarts();
  147.                         log_info('ログイン後処理2');
  148.                         $qtyInCart 0;
  149.                         log_info('ログイン後処理3');
  150.                         foreach ($Carts as $Cart) {
  151.                             $qtyInCart += $Cart->getTotalQuantity();
  152.                         }
  153.                         log_info('ログイン後処理4');
  154.                         //
  155.                         $em $this->entityManager;
  156.                         $conn $em->getConnection();
  157.                         log_info('ログイン後処理5');
  158.                         // 可逆変換
  159.                         $aes_key getenv("API_AES_KEY");
  160.                         $user_id openssl_decrypt($user_id,'aes-256-ecb',$aes_key);
  161.                         $stmt $conn->prepare('SELECT * FROM dtb_customer WHERE id = :id;');
  162.                         $result $stmt->execute([':id' => $user_id]);
  163.                         log_info('ログイン後処理6');
  164.                         $row $result->fetch();
  165.                         if ($row) {
  166.                             log_info('ログイン後処理7',["id" => $row["id"]]);
  167.                             $Customer $this->customerRepository->find($row["id"]);
  168.                             // $Customer
  169.                             //     ->setSalt($row["salt"])
  170.                             //     ->setPassword($row["password"])
  171.                             //     ->setSecretKey($row["secret_key"])
  172.                             //     ->setPoint($row["point"]);
  173.                             log_info('ログイン後処理8',["Customer" => $Customer]);
  174.                             $this->entityManager->persist($Customer);
  175.                             $this->entityManager->flush();
  176.                             $token = new UsernamePasswordToken($Customernull'customer', ['ROLE_USER']);
  177.                             $this->tokenStorage->setToken($token);
  178.                             $request->getSession()->migrate(true);
  179.                             log_info('ログイン後処理9',["token" => $token]);
  180.                             if ($qtyInCart) {
  181.                                 $this->cartService->save();
  182.                             }
  183.                             log_info('ログイン済に変更', [$this->getUser()->getId()]);
  184.                         }
  185.                     }
  186.                 }
  187.             }
  188.         }
  189.         return [];
  190.     }
  191. }