/** * Check Captcha On Forgot Password Page * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $captchaModel = $this->helper->getCaptcha(self::FORM_ID); if ($captchaModel->isRequired()) { /** @var \Magento\Framework\App\Action\Action $controller */ $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) { $customerId = $this->customerSession->getCustomerId(); $this->authentication->processAuthenticationFailure($customerId); if ($this->authentication->isLocked($customerId)) { $this->customerSession->logout(); $this->customerSession->start(); $message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email')); $this->messageManager->addError($message); } $this->messageManager->addError(__('Incorrect CAPTCHA')); $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->redirect->redirect($controller->getResponse(), '*/*/edit'); } } $customer = $this->customerSession->getCustomer(); $login = $customer->getEmail(); $captchaModel->logAttempt($login); return $this; }