From c8ad86753649430c3531a0a22ab92e29df338a8f Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 20 Mar 2020 13:44:07 +0200 Subject: [PATCH 1/3] security-package/issues/154: Add reCAPTCHA support for customer acccount edit. --- .../Observer/EditCustomerObserver.php | 70 +++++++++++++++++++ ReCaptchaCustomer/etc/adminhtml/system.xml | 5 ++ ReCaptchaCustomer/etc/config.xml | 1 + ReCaptchaCustomer/etc/frontend/events.xml | 3 + .../frontend/layout/customer_account_edit.xml | 29 ++++++++ .../view/frontend/web/css/source/_module.less | 2 +- 6 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 ReCaptchaCustomer/Observer/EditCustomerObserver.php create mode 100644 ReCaptchaCustomer/view/frontend/layout/customer_account_edit.xml diff --git a/ReCaptchaCustomer/Observer/EditCustomerObserver.php b/ReCaptchaCustomer/Observer/EditCustomerObserver.php new file mode 100644 index 00000000..88c6beec --- /dev/null +++ b/ReCaptchaCustomer/Observer/EditCustomerObserver.php @@ -0,0 +1,70 @@ +url = $url; + $this->isCaptchaEnabled = $isCaptchaEnabled; + $this->requestHandler = $requestHandler; + } + + /** + * @param Observer $observer + * @return void + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function execute(Observer $observer): void + { + $key = 'customer_edit'; + if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) { + /** @var Action $controller */ + $controller = $observer->getControllerAction(); + $request = $controller->getRequest(); + $response = $controller->getResponse(); + $redirectOnFailureUrl = $this->url->getUrl('*/*/edit', ['_secure' => true]); + + $this->requestHandler->execute($key, $request, $response, $redirectOnFailureUrl); + } + } +} diff --git a/ReCaptchaCustomer/etc/adminhtml/system.xml b/ReCaptchaCustomer/etc/adminhtml/system.xml index c83b515a..2d109bd9 100644 --- a/ReCaptchaCustomer/etc/adminhtml/system.xml +++ b/ReCaptchaCustomer/etc/adminhtml/system.xml @@ -25,6 +25,11 @@ Magento\ReCaptchaApi\Model\OptionSource\Type + + + Magento\ReCaptchaApi\Model\OptionSource\Type + diff --git a/ReCaptchaCustomer/etc/config.xml b/ReCaptchaCustomer/etc/config.xml index e3ead5e4..11ee5351 100644 --- a/ReCaptchaCustomer/etc/config.xml +++ b/ReCaptchaCustomer/etc/config.xml @@ -13,6 +13,7 @@ + diff --git a/ReCaptchaCustomer/etc/frontend/events.xml b/ReCaptchaCustomer/etc/frontend/events.xml index aec4e0a7..8166d9b6 100644 --- a/ReCaptchaCustomer/etc/frontend/events.xml +++ b/ReCaptchaCustomer/etc/frontend/events.xml @@ -16,6 +16,9 @@ + + + diff --git a/ReCaptchaCustomer/view/frontend/layout/customer_account_edit.xml b/ReCaptchaCustomer/view/frontend/layout/customer_account_edit.xml new file mode 100644 index 00000000..11a1de9a --- /dev/null +++ b/ReCaptchaCustomer/view/frontend/layout/customer_account_edit.xml @@ -0,0 +1,29 @@ + + + + + + + + customer_edit + + + + Magento_ReCaptchaFrontendUi/js/reCaptcha + + + + + + + + diff --git a/ReCaptchaCustomer/view/frontend/web/css/source/_module.less b/ReCaptchaCustomer/view/frontend/web/css/source/_module.less index 8ef62177..997ed413 100644 --- a/ReCaptchaCustomer/view/frontend/web/css/source/_module.less +++ b/ReCaptchaCustomer/view/frontend/web/css/source/_module.less @@ -2,7 +2,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -.login-container, .form-login { +.login-container, .form-login, .form-edit-account { .g-recaptcha { margin-bottom: 10px !important; } From dfa87e914e85e16c015f9eefb63b6025571c533d Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 22 Jul 2020 19:03:38 -0500 Subject: [PATCH 2/3] security-package/issues/154: Add reCAPTCHA support for customer account edit --- ReCaptchaCustomer/Observer/EditCustomerObserver.php | 6 +++++- ReCaptchaCustomer/view/frontend/web/css/source/_module.less | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ReCaptchaCustomer/Observer/EditCustomerObserver.php b/ReCaptchaCustomer/Observer/EditCustomerObserver.php index 88c6beec..6ab19f0e 100644 --- a/ReCaptchaCustomer/Observer/EditCustomerObserver.php +++ b/ReCaptchaCustomer/Observer/EditCustomerObserver.php @@ -15,7 +15,9 @@ use Magento\ReCaptchaUi\Model\RequestHandlerInterface; /** - * EditCustomerObserver + * NewsletterObserver + * + * Process the response during customer account editing */ class EditCustomerObserver implements ObserverInterface { @@ -50,6 +52,8 @@ public function __construct( } /** + * @inheritdoc + * * @param Observer $observer * @return void * @throws \Magento\Framework\Exception\LocalizedException diff --git a/ReCaptchaCustomer/view/frontend/web/css/source/_module.less b/ReCaptchaCustomer/view/frontend/web/css/source/_module.less index 997ed413..f2958ae5 100644 --- a/ReCaptchaCustomer/view/frontend/web/css/source/_module.less +++ b/ReCaptchaCustomer/view/frontend/web/css/source/_module.less @@ -2,7 +2,9 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -.login-container, .form-login, .form-edit-account { +.login-container, +.form-login, +.form-edit-account { .g-recaptcha { margin-bottom: 10px !important; } From 3e798f95e00de52d9eeaa6686ef51257310216ad Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Thu, 23 Jul 2020 10:42:44 +0300 Subject: [PATCH 3/3] security-package/issues/154: Add reCAPTCHA support for customer account edit. --- ReCaptchaCustomer/etc/adminhtml/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReCaptchaCustomer/etc/adminhtml/system.xml b/ReCaptchaCustomer/etc/adminhtml/system.xml index e16615ce..27b3bd28 100644 --- a/ReCaptchaCustomer/etc/adminhtml/system.xml +++ b/ReCaptchaCustomer/etc/adminhtml/system.xml @@ -28,7 +28,7 @@ - Magento\ReCaptchaApi\Model\OptionSource\Type + Magento\ReCaptchaAdminUi\Model\OptionSource\Type