|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\ReCaptchaCustomer\Observer; |
| 9 | + |
| 10 | +use Magento\Framework\App\Action\Action; |
| 11 | +use Magento\Framework\Event\Observer; |
| 12 | +use Magento\Framework\Event\ObserverInterface; |
| 13 | +use Magento\Framework\UrlInterface; |
| 14 | +use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface; |
| 15 | +use Magento\ReCaptchaUi\Model\RequestHandlerInterface; |
| 16 | + |
| 17 | +/** |
| 18 | + * EditCustomerObserver |
| 19 | + */ |
| 20 | +class EditCustomerObserver implements ObserverInterface |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @var UrlInterface |
| 24 | + */ |
| 25 | + private $url; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var IsCaptchaEnabledInterface |
| 29 | + */ |
| 30 | + private $isCaptchaEnabled; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var RequestHandlerInterface |
| 34 | + */ |
| 35 | + private $requestHandler; |
| 36 | + |
| 37 | + /** |
| 38 | + * @param UrlInterface $url |
| 39 | + * @param IsCaptchaEnabledInterface $isCaptchaEnabled |
| 40 | + * @param RequestHandlerInterface $requestHandler |
| 41 | + */ |
| 42 | + public function __construct( |
| 43 | + UrlInterface $url, |
| 44 | + IsCaptchaEnabledInterface $isCaptchaEnabled, |
| 45 | + RequestHandlerInterface $requestHandler |
| 46 | + ) { |
| 47 | + $this->url = $url; |
| 48 | + $this->isCaptchaEnabled = $isCaptchaEnabled; |
| 49 | + $this->requestHandler = $requestHandler; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @param Observer $observer |
| 54 | + * @return void |
| 55 | + * @throws \Magento\Framework\Exception\LocalizedException |
| 56 | + */ |
| 57 | + public function execute(Observer $observer): void |
| 58 | + { |
| 59 | + $key = 'customer_edit'; |
| 60 | + if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) { |
| 61 | + /** @var Action $controller */ |
| 62 | + $controller = $observer->getControllerAction(); |
| 63 | + $request = $controller->getRequest(); |
| 64 | + $response = $controller->getResponse(); |
| 65 | + $redirectOnFailureUrl = $this->url->getUrl('*/*/edit', ['_secure' => true]); |
| 66 | + |
| 67 | + $this->requestHandler->execute($key, $request, $response, $redirectOnFailureUrl); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments