diff --git a/Plugin/CustomerAuthenticated.php b/Plugin/CustomerAuthenticated.php
index 66313fc..61def9c 100644
--- a/Plugin/CustomerAuthenticated.php
+++ b/Plugin/CustomerAuthenticated.php
@@ -181,7 +181,7 @@ public function aroundAuthenticate(
}
// force redirect
- return $this->_response->create()->setRedirect($urlRedirect)->sendResponse();
+ return $urlRedirect;
}
return $result;
diff --git a/Plugin/CustomerLoginPost.php b/Plugin/CustomerLoginPost.php
new file mode 100644
index 0000000..f2ac484
--- /dev/null
+++ b/Plugin/CustomerLoginPost.php
@@ -0,0 +1,247 @@
+formKeyValidator = $formKeyValidator;
+ $this->session = $customerSession;
+ $this->resultRedirectFactory = $resultRedirectFactory;
+ $this->customerAccountManagement = $customerAccountManagement;
+ $this->cookieMetadataManager = $cookieMetadataManager;
+ $this->cookieMetadataFactory = $cookieMetadataFactory;
+ $this->accountRedirect = $accountRedirect;
+ $this->scopeConfig = $scopeConfig;
+ $this->_redirect = $_redirect;
+ $this->messageManager = $messageManager;
+ $this->customerUrl = $customerUrl;
+ }
+
+ public function aroundExecute(LoginPost $loginPost, $result)
+ {
+ if ($this->session->isLoggedIn() || !$this->formKeyValidator->validate($loginPost->getRequest())) {
+ /** @var Redirect $resultRedirect */
+ $resultRedirect = $this->resultRedirectFactory->create();
+ $resultRedirect->setPath('*/*/');
+ return $resultRedirect;
+ }
+
+ if ($loginPost->getRequest()->isPost()) {
+ $login = $loginPost->getRequest()->getPost('login');
+ if (!empty($login['username']) && !empty($login['password'])) {
+ try {
+ $resultAuth = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
+ if ($resultAuth instanceof CustomerInterface) {
+ $customer = $resultAuth;
+ } else {
+ $resultRedirect = $this->resultRedirectFactory->create();
+ $resultRedirect->setPath($resultAuth);
+ return $resultRedirect;
+ }
+
+ $this->session->setCustomerDataAsLoggedIn($customer);
+ if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
+ $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
+ $metadata->setPath('/');
+ $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
+ }
+ $redirectUrl = $this->accountRedirect->getRedirectCookie();
+ if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectUrl) {
+ $this->accountRedirect->clearRedirectCookie();
+ $resultRedirect = $this->resultRedirectFactory->create();
+ // URL is checked to be internal in $this->_redirect->success()
+ $resultRedirect->setUrl($this->_redirect->success($redirectUrl));
+ return $resultRedirect;
+ }
+ } catch (EmailNotConfirmedException $e) {
+ $this->messageManager->addComplexErrorMessage(
+ 'confirmAccountErrorMessage',
+ ['url' => $this->customerUrl->getEmailConfirmationUrl($login['username'])]
+ );
+ $this->session->setUsername($login['username']);
+ } catch (AuthenticationException $e) {
+ $message = __(
+ 'The account sign-in was incorrect or your account is disabled temporarily. '
+ . 'Please wait and try again later.'
+ );
+ } catch (LocalizedException $e) {
+ $message = $e->getMessage();
+ } catch (\Exception $e) {
+ // PA DSS violation: throwing or logging an exception here can disclose customer password
+ $this->messageManager->addErrorMessage(
+ __('An unspecified error occurred. Please contact us for assistance.')
+ );
+ } finally {
+ if (isset($message)) {
+ $this->messageManager->addErrorMessage($message);
+ $this->session->setUsername($login['username']);
+ }
+ }
+ } else {
+ $this->messageManager->addErrorMessage(__('A login and a password are required.'));
+ }
+ }
+
+ return $this->accountRedirect->getRedirect();
+
+ }
+
+ /**
+ * @return PhpCookieManager|mixed
+ */
+ public function getCookieManager()
+ {
+ if (!$this->cookieMetadataManager) {
+ $this->cookieMetadataManager = \Magento\Framework\App\ObjectManager::getInstance()->get(
+ PhpCookieManager::class
+ );
+ }
+ return $this->cookieMetadataManager;
+ }
+
+ /**
+ * @return CookieMetadataFactory|mixed
+ */
+ public function getCookieMetadataFactory()
+ {
+ if (!$this->cookieMetadataFactory) {
+ $this->cookieMetadataFactory = \Magento\Framework\App\ObjectManager::getInstance()->get(
+ CookieMetadataFactory::class
+ );
+ }
+ return $this->cookieMetadataFactory;
+ }
+
+ /**
+ * @return ScopeConfigInterface|mixed
+ */
+ private function getScopeConfig()
+ {
+ if (!($this->scopeConfig instanceof \Magento\Framework\App\Config\ScopeConfigInterface)) {
+ return \Magento\Framework\App\ObjectManager::getInstance()->get(
+ \Magento\Framework\App\Config\ScopeConfigInterface::class
+ );
+ } else {
+ return $this->scopeConfig;
+ }
+ }
+}
diff --git a/etc/di.xml b/etc/di.xml
index d620ecb..e3c0f74 100755
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -1,55 +1,58 @@
-
-
-
-
-
-
- - Mageplaza\CustomerApproval\Console\Command\Approve
-
-
-
-
-
-
- - Mageplaza\CustomerApproval\Console\Command\NotApprove
-
-
-
-
-
-
- - Mageplaza\CustomerApproval\Console\Command\Reindex
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+ - Mageplaza\CustomerApproval\Console\Command\Approve
+
+
+
+
+
+
+ - Mageplaza\CustomerApproval\Console\Command\NotApprove
+
+
+
+
+
+
+ - Mageplaza\CustomerApproval\Console\Command\Reindex
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+