diff --git a/app/code/Magento/LoginAsCustomer/Api/AuthenticateCustomerInterface.php b/app/code/Magento/LoginAsCustomer/Api/AuthenticateCustomerInterface.php
new file mode 100644
index 0000000000000..da3c519064995
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/Api/AuthenticateCustomerInterface.php
@@ -0,0 +1,23 @@
+loginModel = $loginModel;
- }
-
/**
* Login As Customer log grid action
*
@@ -59,8 +40,6 @@ public function execute():ResultInterface
return $resultForward;
}
- $this->loginModel->deleteNotUsed();
-
/** @var Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('Magento_LoginAsCustomer::login_log')
diff --git a/app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Login.php b/app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Login.php
index 8c3f0969cfbe6..a260000237f9e 100755
--- a/app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Login.php
+++ b/app/code/Magento/LoginAsCustomer/Controller/Adminhtml/Login/Login.php
@@ -11,6 +11,9 @@
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Backend\App\Action;
+use Magento\Customer\Api\CustomerRepositoryInterface;
+use Magento\Framework\Exception\NoSuchEntityException;
+use Magento\LoginAsCustomer\Api\CreateSecretInterface;
/**
* Login as customer action
@@ -27,11 +30,6 @@ class Login extends Action implements HttpGetActionInterface, HttpPostActionInte
*/
const ADMIN_RESOURCE = 'Magento_LoginAsCustomer::login_button';
- /**
- * @var \Magento\LoginAsCustomer\Model\Login
- */
- private $loginModel;
-
/**
* @var \Magento\Backend\Model\Auth\Session
*/
@@ -47,34 +45,47 @@ class Login extends Action implements HttpGetActionInterface, HttpPostActionInte
*/
private $url;
+ /**
+ * @var CustomerRepositoryInterface
+ */
+ private $customerRepository;
+
/**
* @var \Magento\LoginAsCustomer\Model\Config
*/
private $config;
+ /**
+ * @var CreateSecretInterface
+ */
+ private $createSecretProcessor;
+
/**
* Login constructor.
* @param \Magento\Backend\App\Action\Context $context
- * @param \Magento\LoginAsCustomer\Model\Login $loginModel
* @param \Magento\Backend\Model\Auth\Session $authSession
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Url $url
- * @param \Magento\LoginAsCustomer\Model\Config $config
+ * @param CustomerRepositoryInterface $customerRepository
+ * @param \Magento\LoginAsCustomer\Model\Config $config,
+ * @param CreateSecretInterface $createSecretProcessor
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
- \Magento\LoginAsCustomer\Model\Login $loginModel,
\Magento\Backend\Model\Auth\Session $authSession,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Url $url,
- \Magento\LoginAsCustomer\Model\Config $config
+ CustomerRepositoryInterface $customerRepository,
+ \Magento\LoginAsCustomer\Model\Config $config,
+ CreateSecretInterface $createSecretProcessor
) {
parent::__construct($context);
- $this->loginModel = $loginModel;
$this->authSession = $authSession;
$this->storeManager = $storeManager;
$this->url = $url;
+ $this->customerRepository = $customerRepository;
$this->config = $config;
+ $this->createSecretProcessor = $createSecretProcessor;
}
/**
@@ -84,48 +95,45 @@ public function __construct(
*/
public function execute(): ResultInterface
{
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultRedirectFactory->create();
+
+ if (!$this->config->isEnabled()) {
+ $this->messageManager->addErrorMessage(__('Login As Customer is disabled.'));
+ return $resultRedirect->setPath('customer/index/index');
+ }
+
$request = $this->getRequest();
+
$customerId = (int) $request->getParam('customer_id');
if (!$customerId) {
$customerId = (int) $request->getParam('entity_id');
}
- /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
- $resultRedirect = $this->resultRedirectFactory->create();
-
- if (!$this->config->isEnabled()) {
- $this->messageManager->addErrorMessage(__('Login As Customer is disabled.'));
+ try {
+ $customer = $this->customerRepository->getById($customerId);
+ } catch (NoSuchEntityException $e) {
+ $this->messageManager->addErrorMessage(__('Customer with this ID are no longer exist.'));
return $resultRedirect->setPath('customer/index/index');
}
$customerStoreId = $request->getParam('store_id');
-
if (!isset($customerStoreId) && $this->config->isManualChoiceEnabled()) {
$this->messageManager->addNoticeMessage(__('Please select a Store View to login in.'));
return $resultRedirect->setPath('loginascustomer/login/manual', ['entity_id' => $customerId ]);
}
- $login = $this->loginModel->setCustomerId($customerId);
-
- $login->deleteNotUsed();
-
- $customer = $login->getCustomer();
-
- if (!$customer->getId()) {
- $this->messageManager->addErrorMessage(__('Customer with this ID are no longer exist.'));
- return $resultRedirect->setPath('customer/index/index');
- }
$user = $this->authSession->getUser();
- $login->generate($user->getId());
- $store = $this->storeManager->getStore();
+ $secret = $this->createSecretProcessor->execute($customerId, (int)$user->getId());
+ $store = $this->storeManager->getStore();
if (null === $store) {
$store = $this->storeManager->getDefaultStoreView();
}
$redirectUrl = $this->url->setScope($store)
- ->getUrl('loginascustomer/login/index', ['secret' => $login->getSecret(), '_nosid' => true]);
+ ->getUrl('loginascustomer/login/index', ['secret' => $secret, '_nosid' => true]);
return $resultRedirect->setUrl($redirectUrl);
}
diff --git a/app/code/Magento/LoginAsCustomer/Controller/Login/Index.php b/app/code/Magento/LoginAsCustomer/Controller/Login/Index.php
index dc3affa70e3a2..9fc30ac277cfe 100755
--- a/app/code/Magento/LoginAsCustomer/Controller/Login/Index.php
+++ b/app/code/Magento/LoginAsCustomer/Controller/Login/Index.php
@@ -11,11 +11,15 @@
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
+use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Exception\LocalizedException;
+use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Message\ManagerInterface;
-use Magento\LoginAsCustomer\Model\Login;
use Psr\Log\LoggerInterface;
+use Magento\LoginAsCustomer\Api\GetAuthenticateDataInterface;
+use Magento\LoginAsCustomer\Api\AuthenticateCustomerInterface;
+use Magento\LoginAsCustomer\Api\DeleteSecretInterface;
/**
* Login As Customer storefront login action
@@ -33,9 +37,24 @@ class Index implements HttpGetActionInterface
private $request;
/**
- * @var Login
+ * @var CustomerRepositoryInterface
*/
- private $loginModel;
+ private $customerRepository;
+
+ /**
+ * @var GetAuthenticateDataInterface
+ */
+ private $getAuthenticateDataProcessor;
+
+ /**
+ * @var AuthenticateCustomerInterface
+ */
+ private $authenticateCustomerProcessor;
+
+ /**
+ * @var DeleteSecretInterface
+ */
+ private $deleteSecretProcessor;
/**
* @var ManagerInterface
@@ -50,20 +69,29 @@ class Index implements HttpGetActionInterface
/**
* @param ResultFactory $resultFactory
* @param RequestInterface $request
- * @param Login $loginModel
+ * @param CustomerRepositoryInterface $customerRepository
+ * @param GetAuthenticateDataInterface $getAuthenticateDataProcessor
+ * @param AuthenticateCustomerInterface $authenticateCustomerProcessor
+ * @param DeleteSecretInterface $deleteSecretProcessor
* @param ManagerInterface $messageManager
* @param LoggerInterface $logger
*/
public function __construct(
ResultFactory $resultFactory,
RequestInterface $request,
- Login $loginModel,
+ CustomerRepositoryInterface $customerRepository,
+ GetAuthenticateDataInterface $getAuthenticateDataProcessor,
+ AuthenticateCustomerInterface $authenticateCustomerProcessor,
+ DeleteSecretInterface $deleteSecretProcessor,
ManagerInterface $messageManager,
LoggerInterface $logger
) {
$this->resultFactory = $resultFactory;
$this->request = $request;
- $this->loginModel = $loginModel;
+ $this->customerRepository = $customerRepository;
+ $this->getAuthenticateDataProcessor = $getAuthenticateDataProcessor;
+ $this->authenticateCustomerProcessor = $authenticateCustomerProcessor;
+ $this->deleteSecretProcessor = $deleteSecretProcessor;
$this->messageManager = $messageManager;
$this->logger = $logger;
}
@@ -79,11 +107,35 @@ public function execute(): ResultInterface
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
try {
- $login = $this->initLogin();
- $login->authenticateCustomer();
+ $secret = $this->request->getParam('secret');
+ if (!$secret || !is_string($secret)) {
+ throw new LocalizedException(__('Cannot login to account. No secret key provided.'));
+ }
+
+ /* Can throw LocalizedException */
+ $authenticateData = $this->getAuthenticateDataProcessor->execute($secret);
+
+ $this->deleteSecretProcessor->execute($secret);
+
+ try {
+ $customer = $this->customerRepository->getById($authenticateData['customer_id']);
+ } catch (NoSuchEntityException $e) {
+ throw new LocalizedException(__('Customer are no longer exist.'));
+ }
+
+ $loggedIn = $this->authenticateCustomerProcessor->execute(
+ (int)$authenticateData['customer_id'],
+ (int)$authenticateData['admin_id']
+ );
+
+
+ if (!$loggedIn) {
+ throw new LocalizedException(__('Login was not successful.'));
+ }
+
$this->messageManager->addSuccessMessage(
- __('You are logged in as customer: %1', $login->getCustomer()->getName())
+ __('You are logged in as customer: %1', $customer->getFirstname() . ' ' . $customer->getLastname())
);
$resultRedirect->setPath('*/*/proceed');
@@ -98,26 +150,4 @@ public function execute(): ResultInterface
}
return $resultRedirect;
}
-
- /**
- * Init login info
- *
- * @return Login
- * @throws LocalizedException
- */
- private function initLogin(): Login
- {
- $secret = $this->request->getParam('secret');
- if (!$secret) {
- throw new LocalizedException(__('Cannot login to account. No secret key provided.'));
- }
-
- $login = $this->loginModel->loadNotUsed($secret);
-
- if ($login->getId()) {
- return $login;
- } else {
- throw new LocalizedException(__('Cannot login to account. Secret key is not valid'));
- }
- }
}
diff --git a/app/code/Magento/LoginAsCustomer/Cron/DeleteOldSecrets.php b/app/code/Magento/LoginAsCustomer/Cron/DeleteOldSecrets.php
new file mode 100644
index 0000000000000..b832b45c63b48
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/Cron/DeleteOldSecrets.php
@@ -0,0 +1,50 @@
+deleteOldSecretsProcessor = $deleteOldSecretsProcessor;
+ $this->config = $config;
+ }
+
+ /**
+ * Delete old secret key records
+ */
+ public function execute():void
+ {
+ if ($this->config->isEnabled()) {
+ $this->deleteOldSecretsProcessor->execute();
+ }
+ }
+}
diff --git a/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomer.php b/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomer.php
new file mode 100644
index 0000000000000..4a9aca6f4decf
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/Model/AuthenticateCustomer.php
@@ -0,0 +1,85 @@
+customerSession = $customerSession;
+ $this->cart = $cart;
+ $this->checkoutSession = $checkoutSession;
+ }
+
+ /**
+ * Authenticate a customer by customer ID
+ *
+ * @return bool
+ * @param int $customerId
+ * @param int $adminId
+ */
+ public function execute(int $customerId, int $adminId):bool
+ {
+ if ($this->customerSession->getId()) {
+ /* Logout if logged in */
+ $this->customerSession->logout();
+ } else {
+ $quote = $this->cart->getQuote();
+ /* Remove items from guest cart */
+ foreach ($quote->getAllVisibleItems() as $item) {
+ $this->cart->removeItem($item->getId());
+ }
+ $this->cart->save();
+ }
+
+ $loggedIn = $this->customerSession->loginById($customerId);
+ if ($loggedIn) {
+ $this->customerSession->regenerateId();
+ $this->customerSession->setLoggedAsCustomerAdmindId($adminId);
+ }
+
+ /* Load Customer Quote */
+ $this->checkoutSession->loadCustomerQuote();
+
+ $quote = $this->checkoutSession->getQuote();
+ $quote->setCustomerIsGuest(0);
+ $quote->save();
+
+ return $loggedIn;
+ }
+}
diff --git a/app/code/Magento/LoginAsCustomer/Model/Config.php b/app/code/Magento/LoginAsCustomer/Model/Config.php
index 7b34cc8dcfd7c..85ea8a42c9b57 100644
--- a/app/code/Magento/LoginAsCustomer/Model/Config.php
+++ b/app/code/Magento/LoginAsCustomer/Model/Config.php
@@ -22,6 +22,8 @@ class Config
private const XML_PATH_EXTENSION_ENABLED = 'loginascustomer/general/enabled';
private const ENABLE_STORE_VIEW_MANUAL_CHOICE = 'loginascustomer/general/enable_store_view_manual_choice';
+ public const TIME_FRAME = 60;
+
/**
* @var ScopeConfigInterface
*/
diff --git a/app/code/Magento/LoginAsCustomer/Model/Login.php b/app/code/Magento/LoginAsCustomer/Model/Login.php
index e4c1e55b30a27..847c6cc61a506 100755
--- a/app/code/Magento/LoginAsCustomer/Model/Login.php
+++ b/app/code/Magento/LoginAsCustomer/Model/Login.php
@@ -12,108 +12,6 @@
*/
class Login extends \Magento\Framework\Model\AbstractModel
{
- /**
- * Login tome frame
- */
- const TIME_FRAME = 60;
-
- /**
- * Prefix of model events names
- *
- * @var string
- */
- protected $_eventPrefix = 'login_as_customer_log';
-
- /**
- * Parameter name in event
- *
- * In observe method you can use $observer->getEvent()->getObject() in this case
- *
- * @var string
- */
- protected $_eventObject = 'loginascustomer_login';
-
- /**
- * @var \Magento\Customer\Model\CustomerFactory
- */
- private $_customerFactory;
-
- /**
- * @var \Magento\Customer\Model\Customer
- */
- private $_customer;
-
- /**
- * @var \Magento\Customer\Model\Session
- */
- private $_customerSession;
-
- /**
- * @var \Magento\Checkout\Model\Session
- */
- private $_checkoutSession;
-
- /**
- * @var \Magento\Framework\Stdlib\DateTime\DateTime
- */
- private $_dateTime;
-
- /**
- * @var \Magento\Framework\Math\Random
- */
- private $_random;
-
- /**
- * @var \Magento\Checkout\Model\Cart
- */
- private $cart;
-
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- private $scopeConfig;
-
- /**
- * Initialize dependencies.
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Customer\Model\CustomerFactory $customerFactory
- * @param \Magento\Customer\Model\Session $customerSession
- * @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
- * @param \Magento\Framework\Math\Random $random
- * @param \Magento\Checkout\Model\Cart $cart
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\Model\Context $context,
- \Magento\Framework\Registry $registry,
- \Magento\Customer\Model\CustomerFactory $customerFactory,
- \Magento\Customer\Model\Session $customerSession,
- \Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
- \Magento\Framework\Math\Random $random,
- \Magento\Checkout\Model\Cart $cart,
- \Magento\Checkout\Model\Session $checkoutSession,
- \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
- \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
- \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
- array $data = []
- ) {
- $this->_customerFactory = $customerFactory;
- $this->_customerSession = $customerSession;
- $this->_checkoutSession = $checkoutSession;
- $this->_dateTime = $dateTime;
- $this->_random = $random;
- $this->cart = $cart;
- $this->_checkoutSession = $checkoutSession;
- $this->scopeConfig = $scopeConfig;
-
- parent::__construct($context, $registry, $resource, $resourceCollection, $data);
- }
-
/**
* Initialize resource model
*
@@ -123,118 +21,4 @@ protected function _construct()
{
$this->_init(\Magento\LoginAsCustomer\Model\ResourceModel\Login::class);
}
-
- /**
- * Retrieve not used admin login
- * @param string $secret
- * @return self
- */
- public function loadNotUsed($secret): self
- {
- return $this->getCollection()
- ->addFieldToFilter('secret', $secret)
- ->addFieldToFilter('used', 0)
- ->addFieldToFilter('created_at', ['gt' => $this->getDateTimePoint()])
- ->setPageSize(1)
- ->getFirstItem();
- }
-
- /**
- * Delete not used credentials
- * @return void
- */
- public function deleteNotUsed(): void
- {
- $resource = $this->getResource();
- $resource->getConnection()->delete(
- $resource->getTable('login_as_customer_log'),
- [
- 'created_at < ?' => $this->getDateTimePoint(),
- 'used = ?' => 0,
- ]
- );
- }
-
- /**
- * Retrieve login datetime point
- * @return string
- */
- private function getDateTimePoint(): string
- {
- return date('Y-m-d H:i:s', $this->_dateTime->gmtTimestamp() - self::TIME_FRAME);
- }
-
- /**
- * Retrieve customer
- * @return \Magento\Customer\Model\Customer
- */
- public function getCustomer(): \Magento\Customer\Model\Customer
- {
- if (is_null($this->_customer)) {
- $this->_customer = $this->_customerFactory->create()
- ->load($this->getCustomerId());
- }
- return $this->_customer;
- }
-
- /**
- * Login Customer
- * @return \Magento\Customer\Model\Customer
- */
- public function authenticateCustomer(): \Magento\Customer\Model\Customer
- {
- if ($this->_customerSession->getId()) {
- /* Logout if logged in */
- $this->_customerSession->logout();
- } else {
- $quote = $this->cart->getQuote();
- /* Remove items from guest cart */
- foreach ($quote->getAllVisibleItems() as $item) {
- $this->cart->removeItem($item->getId());
- }
- $this->cart->save();
- }
-
- $customer = $this->getCustomer();
-
- if (!$customer->getId()) {
- throw new \Exception(__("Customer are no longer exist."), 1);
- }
-
- if ($this->_customerSession->loginById($customer->getId())) {
- $this->_customerSession->regenerateId();
- $this->_customerSession->setLoggedAsCustomerAdmindId(
- $this->getAdminId()
- );
- } else {
- throw new \Exception(__("Cannot login customer."), 1);
- }
-
- /* Load Customer Quote */
- $this->_checkoutSession->loadCustomerQuote();
-
- $quote = $this->_checkoutSession->getQuote();
- $quote->setCustomerIsGuest(0);
- $quote->save();
-
- $this->setUsed(1)->save();
-
- return $customer;
- }
-
- /**
- * Generate new login credentials
- * @param int $adminId
- * @return $this
- */
- public function generate($adminId): self
- {
- return $this->setData([
- 'customer_id' => $this->getCustomerId(),
- 'admin_id' => $adminId,
- 'secret' => $this->_random->getRandomString(64),
- 'used' => 0,
- 'created_at' => $this->_dateTime->gmtTimestamp(),
- ])->save();
- }
}
diff --git a/app/code/Magento/LoginAsCustomer/Model/ResourceModel/CreateSecret.php b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/CreateSecret.php
new file mode 100644
index 0000000000000..c17c080320abb
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/CreateSecret.php
@@ -0,0 +1,73 @@
+resourceConnection = $resourceConnection;
+ $this->dateTime = $dateTime;
+ $this->random = $random;
+ }
+
+ /**
+ * Create a new secret key
+ * @return string
+ * @param int $customerId
+ * @param int $adminId
+ */
+ public function execute(int $customerId, int $adminId):string
+ {
+ $connection = $this->resourceConnection->getConnection();
+ $tableName = $this->resourceConnection->getTableName('login_as_customer');
+
+ $secret = $this->random->getRandomString(64);
+
+ $connection->insert(
+ $tableName,
+ [
+ 'customer_id' => $customerId,
+ 'admin_id' => $adminId,
+ 'secret' => $secret,
+ 'created_at' => $this->dateTime->gmtDate(),
+ ]
+ );
+
+ return $secret;
+ }
+}
diff --git a/app/code/Magento/LoginAsCustomer/Model/ResourceModel/DeleteOldSecrets.php b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/DeleteOldSecrets.php
new file mode 100644
index 0000000000000..92a9223c1a822
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/DeleteOldSecrets.php
@@ -0,0 +1,58 @@
+resourceConnection = $resourceConnection;
+ $this->dateTime = $dateTime;
+ }
+
+ /**
+ * Delete old secret key records
+ */
+ public function execute():void
+ {
+ $connection = $this->resourceConnection->getConnection();
+ $tableName = $this->resourceConnection->getTableName('login_as_customer');
+
+ $timePoint = date('Y-m-d H:i:s', $this->dateTime->gmtTimestamp() - Config::TIME_FRAME);
+
+ $connection->delete(
+ $tableName,
+ [
+ 'created_at < ?' => $timePoint
+ ]
+ );
+ }
+}
diff --git a/app/code/Magento/LoginAsCustomer/Model/ResourceModel/DeleteSecret.php b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/DeleteSecret.php
new file mode 100644
index 0000000000000..0fb5f6a70214c
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/DeleteSecret.php
@@ -0,0 +1,47 @@
+resourceConnection = $resourceConnection;
+ }
+
+ /**
+ * Delete old secret key records
+ */
+ public function execute(string $secretKey):void
+ {
+ $connection = $this->resourceConnection->getConnection();
+ $tableName = $this->resourceConnection->getTableName('login_as_customer');
+
+ $connection->delete(
+ $tableName,
+ [
+ 'secret = ?' => $secretKey
+ ]
+ );
+ }
+}
diff --git a/app/code/Magento/LoginAsCustomer/Model/ResourceModel/GetAuthenticateData.php b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/GetAuthenticateData.php
new file mode 100644
index 0000000000000..59ab0f11d6ba7
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/GetAuthenticateData.php
@@ -0,0 +1,70 @@
+resourceConnection = $resourceConnection;
+ $this->dateTime = $dateTime;
+ }
+
+ /**
+ * Load logic details based on secret key
+ * @return array
+ * @throws LocalizedException
+ * @param string $secretKey
+ */
+ public function execute(string $secretKey):array
+ {
+ $connection = $this->resourceConnection->getConnection();
+ $tableName = $this->resourceConnection->getTableName('login_as_customer');
+
+ $timePoint = date('Y-m-d H:i:s', $this->dateTime->gmtTimestamp() - Config::TIME_FRAME);
+
+ $select = $connection->select()
+ ->from(['main_table' => $tableName])
+ ->where('main_table.secret = ?', $secretKey)
+ ->where('main_table.created_at > ?', $timePoint)
+ ->limit(1);
+
+ $data = $connection->fetchRow($select);
+
+ if (!$data) {
+ throw new LocalizedException(__('Secret key is not valid.'));
+ }
+
+
+ return $data;
+ }
+}
diff --git a/app/code/Magento/LoginAsCustomer/Model/ResourceModel/Login.php b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/Login.php
index b61e595a29212..aa8d4dc554894 100755
--- a/app/code/Magento/LoginAsCustomer/Model/ResourceModel/Login.php
+++ b/app/code/Magento/LoginAsCustomer/Model/ResourceModel/Login.php
@@ -20,6 +20,6 @@ class Login extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
*/
protected function _construct()
{
- $this->_init('login_as_customer_log', 'login_id');
+ $this->_init('login_as_customer', 'login_id');
}
}
diff --git a/app/code/Magento/LoginAsCustomer/etc/crontab.xml b/app/code/Magento/LoginAsCustomer/etc/crontab.xml
new file mode 100644
index 0000000000000..b2fa75253f241
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/etc/crontab.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+ 15 * * * *
+
+
+
diff --git a/app/code/Magento/LoginAsCustomer/etc/db_schema.xml b/app/code/Magento/LoginAsCustomer/etc/db_schema.xml
index c4c8e8f01a1da..1b457fc2ddcb8 100644
--- a/app/code/Magento/LoginAsCustomer/etc/db_schema.xml
+++ b/app/code/Magento/LoginAsCustomer/etc/db_schema.xml
@@ -7,7 +7,7 @@
-->
-
+
-
diff --git a/app/code/Magento/LoginAsCustomer/etc/db_schema_whitelist.json b/app/code/Magento/LoginAsCustomer/etc/db_schema_whitelist.json
index bb05d8fbb5a0b..e723c1c73b6ff 100644
--- a/app/code/Magento/LoginAsCustomer/etc/db_schema_whitelist.json
+++ b/app/code/Magento/LoginAsCustomer/etc/db_schema_whitelist.json
@@ -1,11 +1,10 @@
{
- "login_as_customer_log": {
+ "login_as_customer": {
"column": {
"login_id": true,
"customer_id": true,
"admin_id": true,
"secret": true,
- "used": true,
"created_at": true
},
"index": {
@@ -17,4 +16,4 @@
"PRIMARY": true
}
}
-}
\ No newline at end of file
+}
diff --git a/app/code/Magento/LoginAsCustomer/etc/di.xml b/app/code/Magento/LoginAsCustomer/etc/di.xml
new file mode 100755
index 0000000000000..4eb46a8be7e53
--- /dev/null
+++ b/app/code/Magento/LoginAsCustomer/etc/di.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+