- $loginParams = $controller->getRequest()->getPost('login');
- $login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
- if ($captchaModel->isRequired($login)) {
- $word = $this->captchaStringResolver->resolve($controller->getRequest(), $formId);
- if (!$captchaModel->isCorrect($word)) {
- try {
- $customer = $this->getCustomerRepository()->get($login);
- $this->getAccountManagementHelper()->processCustomerLockoutData($customer->getId());
- $this->getCustomerRepository()->save($customer);
- } catch (NoSuchEntityException $e) {
- //do nothing as customer existance is validated later in authenticate method
- }
- $this->messageManager->addError(__('Incorrect CAPTCHA'));
- $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
- $this->_session->setUsername($login);
- $beforeUrl = $this->_session->getBeforeAuthUrl();
- $url = $beforeUrl ? $beforeUrl : $this->_customerUrl->getLoginUrl();
- $controller->getResponse()->setRedirect($url);
- }
- }
- $captchaModel->logAttempt($login);