/**
  * Customer locking implementation
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $username = $observer->getEvent()->getData('username');
     $customer = $this->customerRepository->get($username);
     if ($customer && $customer->getId()) {
         $this->accountManagementHelper->processCustomerLockoutData($customer->getId());
         $this->customerRepository->save($customer);
     }
     return $this;
 }
 /**
  * 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))) {
             try {
                 $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
                 $this->accountManagementHelper->processCustomerLockoutData($customer->getId());
                 $this->customerRepository->save($customer);
             } catch (NoSuchEntityException $e) {
                 //do nothing as customer existance is validated later in authenticate method
             }
             $this->workWithLock();
             $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;
 }
 /**
  * @return void
  */
 public function testCustomerHasFailedMaxNumberOfAttempts()
 {
     $customerId = 1;
     $date = new \DateTime();
     $date->modify('-500 second');
     $formattedDate = $date->format('Y-m-d H:i:s');
     $this->backendConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive([\Magento\Customer\Helper\AccountManagement::LOCKOUT_THRESHOLD_PATH], [\Magento\Customer\Helper\AccountManagement::MAX_FAILURES_PATH])->willReturnOnConsecutiveCalls(10, 5);
     $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure);
     $this->customerSecure->expects($this->once())->method('getFailuresNum')->willReturn(5);
     $this->customerSecure->expects($this->once())->method('getFirstFailure')->willReturn($formattedDate);
     $this->customerSecure->expects($this->once())->method('setLockExpires');
     $this->customerSecure->expects($this->once())->method('setFailuresNum');
     $this->helper->processCustomerLockoutData($customerId);
 }