From 3ccb3144d441821fabcb1cf0722bdf0e49d1ea50 Mon Sep 17 00:00:00 2001 From: Nguyen Huy Phuc Date: Tue, 8 Dec 2020 14:53:31 +0700 Subject: [PATCH 1/7] Fix Recaptcha display error when Age Verification module is enabled --- Block/Captcha.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Block/Captcha.php b/Block/Captcha.php index 7dfbed4..b6d36a8 100644 --- a/Block/Captcha.php +++ b/Block/Captcha.php @@ -92,6 +92,7 @@ public function __construct( public function getForms() { $useLogin = false; + $ageVerification = false; $this->_dataFormId = $this->_helperData->getFormsFrontend(); foreach ($this->_dataFormId as $item => $value) { @@ -116,6 +117,7 @@ public function getForms() $actionName = $this->actionName[5]; break; default: + $ageVerification = true; $actionName = ''; } $this->unsetDataFromId($item, $actionName); @@ -127,7 +129,7 @@ public function getForms() } } - if ($this->isAgeVerificationEnabled()) { + if ($this->isAgeVerificationEnabled() && $ageVerification) { $this->_dataFormId[] = Forms::TYPE_AGEVERIFICATION; } From 16667a27fb31caa23877d3115bb74a9b5e316ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Th=E1=BA=BF=20Vinh?= Date: Fri, 9 Jul 2021 16:02:05 +0700 Subject: [PATCH 2/7] [2.3.7] Change API key and secret key to `Obsecure` type --- Helper/Data.php | 19 ++++++++++++++----- etc/adminhtml/system.xml | 12 ++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 733c675..c7b3f05 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -24,6 +24,7 @@ use Exception; use Magento\Checkout\Helper\Data as CheckoutData; use Magento\Framework\App\Helper\Context; +use Magento\Framework\Encryption\EncryptorInterface; use Magento\Framework\HTTP\Adapter\CurlFactory; use Magento\Framework\ObjectManagerInterface; use Magento\Store\Model\StoreManagerInterface; @@ -51,6 +52,11 @@ class Data extends CoreHelper */ protected $_formPaths; + /** + * @var EncryptorInterface + */ + protected $encryptor; + /** * Data constructor. * @@ -59,16 +65,19 @@ class Data extends CoreHelper * @param StoreManagerInterface $storeManager * @param CurlFactory $curlFactory * @param DefaultFormsPaths $formPaths + * @param EncryptorInterface $encryptor */ public function __construct( Context $context, ObjectManagerInterface $objectManager, StoreManagerInterface $storeManager, CurlFactory $curlFactory, - DefaultFormsPaths $formPaths + DefaultFormsPaths $formPaths, + EncryptorInterface $encryptor ) { $this->_curlFactory = $curlFactory; $this->_formPaths = $formPaths; + $this->encryptor = $encryptor; parent::__construct($context, $objectManager, $storeManager); } @@ -84,7 +93,7 @@ public function __construct( */ public function getVisibleKey($storeId = null) { - return $this->getConfigGeneral('visible/api_key', $storeId); + return $this->encryptor->decrypt($this->getConfigGeneral('visible/api_key', $storeId)); } /** @@ -94,7 +103,7 @@ public function getVisibleKey($storeId = null) */ public function getVisibleSecretKey($storeId = null) { - return $this->getConfigGeneral('visible/api_secret', $storeId); + return $this->encryptor->decrypt($this->getConfigGeneral('visible/api_secret', $storeId)); } /** @@ -226,7 +235,7 @@ public function getFormsFrontend($storeId = null) */ public function getInvisibleKey($storeId = null) { - return $this->getConfigGeneral('invisible/api_key', $storeId); + return $this->encryptor->decrypt($this->getConfigGeneral('invisible/api_key', $storeId)); } /** @@ -236,7 +245,7 @@ public function getInvisibleKey($storeId = null) */ public function getInvisibleSecretKey($storeId = null) { - return $this->getConfigGeneral('invisible/api_secret', $storeId); + return $this->encryptor->decrypt($this->getConfigGeneral('invisible/api_secret', $storeId)); } /** diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c617919..c8d3efd 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -35,22 +35,26 @@ - + + Magento\Config\Model\Config\Backend\Encrypted here.]]> - + + Magento\Config\Model\Config\Backend\Encrypted - + + Magento\Config\Model\Config\Backend\Encrypted here.]]> - + + Magento\Config\Model\Config\Backend\Encrypted From 4a8f90c1c42a0c278f48c3d332e879e3a363a3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Th=E1=BA=BF=20Vinh?= Date: Fri, 9 Jul 2021 16:03:18 +0700 Subject: [PATCH 3/7] [2.3.7] Handle API secret key is null or incorrect --- Observer/Adminhtml/Forgot.php | 3 ++- Observer/Adminhtml/Login.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Observer/Adminhtml/Forgot.php b/Observer/Adminhtml/Forgot.php index 0c5520a..bf7b47a 100644 --- a/Observer/Adminhtml/Forgot.php +++ b/Observer/Adminhtml/Forgot.php @@ -103,7 +103,8 @@ public function execute(Observer $observer) { if ($this->_helperData->isCaptchaBackend() && $this->_request->getParam('g-recaptcha-response') !== null - && in_array('backend_forgotpassword', $this->_helperData->getFormsBackend(), true) + && (in_array('backend_forgotpassword', $this->_helperData->getFormsBackend(), true)) + && ($this->_helperData->getVisibleKey() !== null && $this->_helperData->getVisibleSecretKey() !== null) ) { $controller = $this->_urlInterface->getCurrentUrl(); try { diff --git a/Observer/Adminhtml/Login.php b/Observer/Adminhtml/Login.php index 4643372..bf232d6 100644 --- a/Observer/Adminhtml/Login.php +++ b/Observer/Adminhtml/Login.php @@ -57,7 +57,8 @@ public function __construct( public function execute(Observer $observer) { if ($this->_helperData->isCaptchaBackend() - && in_array('backend_login', $this->_helperData->getFormsBackend(), true) + && (in_array('backend_login', $this->_helperData->getFormsBackend(), true)) + && ($this->_helperData->getVisibleKey() !== null && $this->_helperData->getVisibleSecretKey() !== null) ) { $response = $this->_helperData->verifyResponse('visible'); if (!array_key_exists('success', $response) || empty($response['success'])) { From 41d7f47b353f8bf8ce97478329b5599cce4f583b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Th=E1=BA=BF=20Vinh?= Date: Fri, 9 Jul 2021 16:04:28 +0700 Subject: [PATCH 4/7] [2.3.7] Change `Change Password` to `Edit Account` in field Forms --- Block/Captcha.php | 2 +- Model/System/Config/Source/Frontend/Forms.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Block/Captcha.php b/Block/Captcha.php index b6d36a8..a9c3e23 100644 --- a/Block/Captcha.php +++ b/Block/Captcha.php @@ -113,7 +113,7 @@ public function getForms() case Forms::TYPE_PRODUCTREVIEW: $actionName = $this->actionName[4]; break; - case Forms::TYPE_CHANGEPASSWORD: + case Forms::TYPE_EDITACCOUNT: $actionName = $this->actionName[5]; break; default: diff --git a/Model/System/Config/Source/Frontend/Forms.php b/Model/System/Config/Source/Frontend/Forms.php index 13d11a3..91a64a8 100644 --- a/Model/System/Config/Source/Frontend/Forms.php +++ b/Model/System/Config/Source/Frontend/Forms.php @@ -34,7 +34,7 @@ class Forms implements ArrayInterface const TYPE_CREATE = 'body.customer-account-create #form-validate.form-create-account'; const TYPE_FORGOT = '#form-validate.form.password.forget'; const TYPE_CONTACT = '#contact-form'; - const TYPE_CHANGEPASSWORD = '#form-validate.form.form-edit-account'; + const TYPE_EDITACCOUNT = '#form-validate.form.form-edit-account'; const TYPE_PRODUCTREVIEW = '#review-form'; const TYPE_AGEVERIFICATION = '#mpageverify-form'; const TYPE_FORMSEXTENDED = [ @@ -84,7 +84,7 @@ public function getOptionHash() self::TYPE_CREATE => __('Create User'), self::TYPE_FORGOT => __('Forgot Password'), self::TYPE_CONTACT => __('Contact Us'), - self::TYPE_CHANGEPASSWORD => __('Change Password'), + self::TYPE_EDITACCOUNT => __('Edit Account'), self::TYPE_PRODUCTREVIEW => __('Product Review') ]; if ($this->checkModuleEnable('Mageplaza_AgeVerification')) { @@ -104,7 +104,7 @@ public function defaultForms() self::TYPE_CREATE => 'customer/account/createpost/', self::TYPE_FORGOT => 'customer/account/forgotpasswordpost/', self::TYPE_CONTACT => 'contact/index/post/', - self::TYPE_CHANGEPASSWORD => 'customer/account/editPost/', + self::TYPE_EDITACCOUNT => 'customer/account/editPost/', self::TYPE_PRODUCTREVIEW => 'review/product/post/' ]; if ($this->checkModuleEnable('Mageplaza_AgeVerification')) { From 26ebdc5cf5c89afec54cf81ad3ca3bc4cc4b5fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Th=E1=BA=BF=20Vinh?= Date: Fri, 9 Jul 2021 16:05:37 +0700 Subject: [PATCH 5/7] [2.3.7] Delete Notification at product review page and add compatible with Mageplaza_Osc --- view/frontend/web/js/captcha.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/view/frontend/web/js/captcha.js b/view/frontend/web/js/captcha.js index 4fcc597..c9552fe 100644 --- a/view/frontend/web/js/captcha.js +++ b/view/frontend/web/js/captcha.js @@ -88,6 +88,9 @@ define([ && $(element).prop("tagName").toLowerCase() === 'form') { self.activeForm.push(element); result = true; + } else if (element === '.opc-wrapper.one-step-checkout-wrapper') { + self.activeForm.push(element); + result = true; } }); } @@ -108,7 +111,7 @@ define([ var divCaptcha = $('
'); var divAction = $('.actions-toolbar'); var divError = $('
'); - var checkBox = $(''); + var checkBox = $(''); divError.text($t('You need select captcha')).attr('style', 'display:none;color:red'); divCaptcha.attr('id', 'mp' + '_recaptcha_' + number); @@ -143,6 +146,7 @@ define([ || value === '#social-form-create' || value === '#social-form-password-forget' || value === '.popup-authentication #login-form.form.form-login' + || value === '.opc-wrapper.one-step-checkout-wrapper' || (value === '#review-form' && self.options.type === 'invisible') ) { buttonElement.trigger('click'); @@ -182,8 +186,26 @@ define([ || value === '#social-form-create' || value === '#social-form-password-forget' || value === '.popup-authentication #login-form.form.form-login' + || value === '.opc-wrapper.one-step-checkout-wrapper' || (value === '#review-form' && self.options.type === 'invisible') ) { + if (value === '.opc-wrapper.one-step-checkout-wrapper') { + $('button.checkout').on('click', function (event) { + if (!self.stopSubmit) { + $.each(self.captchaForm, function (form, value) { + if (element.find('#' + value).length > 0) { + grecaptcha.reset(form); + grecaptcha.execute(form); + resetForm = form; + event.preventDefault(event); + event.stopImmediatePropagation(); + + return false; + } + }); + } + }); + } buttonElement.on('click', function (event) { if (!(element.validation() && element.validation('isValid'))) { return; @@ -256,6 +278,7 @@ define([ $.each(self.captchaForm, function (form, value) { if (element.find('#' + value).length > 0) { self.showMessage(divError, 5000); + buttonElement.attr('disabled', false); grecaptcha.reset(form); event.preventDefault(event); event.stopImmediatePropagation(); From f29bcc95daa9547b9f7ff83565ae7b829aec1507 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 13 Aug 2021 17:20:38 +0700 Subject: [PATCH 6/7] Updated labels & content --- README.md | 10 ++++++++++ etc/adminhtml/system.xml | 3 +++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 4abe501..088af64 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,21 @@ A: Yes, you can choose a language code to display reCAPTCHA on the backend. Run the following command in Magento 2 root folder: +With Marketing Automation (recommend): + +``` +composer require mageplaza/module-google-recaptcha mageplaza/module-smtp +php bin/magento setup:upgrade +php bin/magento setup:static-content:deploy +``` + +Without Marketing Automation: ``` composer require mageplaza/module-google-recaptcha php bin/magento setup:upgrade php bin/magento setup:static-content:deploy ``` + ## 4. Google reCAPTCHA highlight features ### Invisible reCAPTCHA diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c8d3efd..83b8ab3 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -32,6 +32,9 @@ Magento\Config\Model\Config\Source\Yesno + One Step Checkout.
+ 1. Increase 25% conversion rate with Layered Navigation
+ 2. Magento stores see upwards of 30% revenue 💰 with AVADA. Learn more]]>
From 9fb83e3f8e1a5c1ec0034ab623fca4ccc2d778cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Th=E1=BA=BF=20Vinh?= Date: Sun, 22 Aug 2021 17:03:56 +0700 Subject: [PATCH 7/7] --update compose.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1ddb209..b8c07df 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "google/recaptcha": "^1.2" }, "type": "magento2-module", - "version": "1.2.2", + "version": "1.2.3", "license": "proprietary", "authors": [ {