|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2024 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + * |
| 6 | + * NOTICE: All information contained herein is, and remains |
| 7 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 8 | + * and technical concepts contained herein are proprietary to Adobe |
| 9 | + * and its suppliers and are protected by all applicable intellectual |
| 10 | + * property laws, including trade secret and copyright laws. |
| 11 | + * Dissemination of this information or reproduction of this material |
| 12 | + * is strictly forbidden unless prior written permission is obtained from |
| 13 | + * Adobe. |
| 14 | + */ |
| 15 | +declare(strict_types=1); |
| 16 | + |
| 17 | +namespace Magento\ReCaptchaResendConfirmationEmail\Observer; |
| 18 | + |
| 19 | +use Magento\Framework\App\Action\Action; |
| 20 | +use Magento\Framework\App\Response\RedirectInterface; |
| 21 | +use Magento\Framework\Event\Observer; |
| 22 | +use Magento\Framework\Event\ObserverInterface; |
| 23 | +use Magento\Framework\Exception\LocalizedException; |
| 24 | +use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface; |
| 25 | +use Magento\ReCaptchaUi\Model\RequestHandlerInterface; |
| 26 | + |
| 27 | +class ResendConfirmationEmailObserver implements ObserverInterface |
| 28 | +{ |
| 29 | + private const KEY = 'resend_confirmation_email'; |
| 30 | + |
| 31 | + /** |
| 32 | + * @param RedirectInterface $redirect |
| 33 | + * @param IsCaptchaEnabledInterface $isCaptchaEnabled |
| 34 | + * @param RequestHandlerInterface $requestHandler |
| 35 | + */ |
| 36 | + public function __construct( |
| 37 | + private readonly RedirectInterface $redirect, |
| 38 | + private readonly IsCaptchaEnabledInterface $isCaptchaEnabled, |
| 39 | + private readonly RequestHandlerInterface $requestHandler |
| 40 | + ) { |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Check captcha result if captcha has been enabled for this endpoint |
| 45 | + * |
| 46 | + * @param Observer $observer |
| 47 | + * @return void |
| 48 | + * @throws LocalizedException |
| 49 | + */ |
| 50 | + public function execute(Observer $observer): void |
| 51 | + { |
| 52 | + if ($this->isCaptchaEnabled->isCaptchaEnabledFor(self::KEY)) { |
| 53 | + /** @var Action $controller */ |
| 54 | + $controller = $observer->getControllerAction(); |
| 55 | + $request = $controller->getRequest(); |
| 56 | + $response = $controller->getResponse(); |
| 57 | + $redirectOnFailureUrl = $this->redirect->getRefererUrl(); |
| 58 | + |
| 59 | + $this->requestHandler->execute(self::KEY, $request, $response, $redirectOnFailureUrl); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments