109 lines
2.8 KiB
PHP
Executable File
109 lines
2.8 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Copyright © JR All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
|
|
namespace JR\ReportIntegration\Service;
|
|
|
|
use JR\ReportIntegration\Helper\Data as Helper;
|
|
use JR\ReportIntegration\Api\Service\RequestServiceInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
use Magento\Customer\Api\AccountManagementInterface;
|
|
use Magento\Framework\Exception\LocalizedException;
|
|
use Magento\Framework\Serialize\Serializer\Json;
|
|
use Magento\Customer\Api\CustomerRepositoryInterface;
|
|
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
|
|
use Magento\Customer\Model\Session;
|
|
|
|
class RequestService implements RequestServiceInterface
|
|
{
|
|
/**
|
|
* @var Json
|
|
*/
|
|
private $json;
|
|
|
|
/**
|
|
* @var Helper
|
|
*/
|
|
private $helper;
|
|
|
|
/**
|
|
* @var AccountManagementInterface
|
|
*/
|
|
private $accountManagement;
|
|
|
|
/**
|
|
* @var CustomerRepositoryInterface
|
|
*/
|
|
private $customerRepository;
|
|
|
|
/**
|
|
* @var CustomerCollectionFactory
|
|
*/
|
|
private $customerCollectionFactory;
|
|
|
|
/**
|
|
* @var Session
|
|
*/
|
|
private $customerSession;
|
|
|
|
/**
|
|
* @var StoreManagerInterface
|
|
*/
|
|
private $storeManager;
|
|
|
|
/**
|
|
* @param CustomerRepositoryInterface
|
|
* @param CustomerCollectionFactory
|
|
* @param Session
|
|
*
|
|
*
|
|
*/
|
|
public function __construct(
|
|
Json $json,
|
|
Helper $helper,
|
|
AccountManagementInterface $accountManagement,
|
|
CustomerRepositoryInterface $customerRepository,
|
|
CustomerCollectionFactory $customerCollectionFactory,
|
|
Session $customerSession,
|
|
StoreManagerInterface $storeManager
|
|
) {
|
|
$this->json = $json;
|
|
$this->helper = $helper;
|
|
$this->accountManagement = $accountManagement;
|
|
$this->customerRepository = $customerRepository;
|
|
$this->customerCollectionFactory = $customerCollectionFactory;
|
|
$this->customerSession = $customerSession;
|
|
$this->storeManager = $storeManager;
|
|
}
|
|
|
|
/**
|
|
* {inheritdoc}
|
|
*/
|
|
public function post($email, $secret, $func, $params = [])
|
|
{
|
|
$this->helper->checkIP();
|
|
|
|
if (strtolower($email) != Helper::INTEGRATION_EMAIL) {
|
|
throw new LocalizedException(__('Unauthorized Access'));
|
|
}
|
|
|
|
try {
|
|
$result = ['error' => false, 'message' => null, 'data' => null];
|
|
if ($this->accountManagement->authenticate($email, $secret)) {
|
|
$result['data'] = call_user_func_array($func, $params);
|
|
} else {
|
|
throw new LocalizedException(__('Login failed'));
|
|
}
|
|
} catch (\Exception $e) {
|
|
$result['error'] = true;
|
|
$result['message'] = $e->getMessage();
|
|
}
|
|
|
|
return $this->json->serialize($result);
|
|
|
|
}
|
|
}
|
|
|