/**
  * Unlock customer on success login attempt.
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Customer\Model\Customer $model */
     $customerModel = $observer->getEvent()->getData('model');
     $customer = $this->customerRepository->getById($customerModel->getId());
     $this->accountManagementHelper->processUnlockData($customer->getId());
     $this->customerRepository->save($customer);
     return $this;
 }
 /**
  * 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;
 }
 /**
  * @return void
  */
 public function testExecute()
 {
     $customerId = 1;
     $observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getData'], [], '', false);
     $observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getData')->with('model')->willReturn($this->customerModelMock);
     $this->customerModelMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->customerRepositoryMock->expects($this->once())->method('getById')->willReturn($this->customerDataMock);
     $this->customerDataMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->accountManagementHelperMock->expects($this->once())->method('processUnlockData')->with($customerId);
     $this->customerRepositoryMock->expects($this->once())->method('save')->with($this->customerDataMock);
     $this->customerLoginSuccessObserver->execute($observerMock);
 }
 /**
  * @return void
  */
 public function testExecute()
 {
     $username = '******';
     $customerId = 1;
     $observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getData'], [], '', false);
     $observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getData')->with('username')->willReturn($username);
     $this->customerRepositoryMock->expects($this->once())->method('get')->with($username)->willReturn($this->customerData);
     $this->customerData->expects($this->exactly(2))->method('getId')->willReturn($customerId);
     $this->accountManagementHelperMock->expects($this->once())->method('processCustomerLockoutData')->with($customerId);
     $this->customerRepositoryMock->expects($this->once())->method('save')->with($this->customerData);
     $this->observer->execute($observerMock);
 }
 /**
  * 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;
 }
 /**
  * Unlock specified customer
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $customerId = $this->getRequest()->getParam('customer_id');
     try {
         // unlock customer
         if ($customerId) {
             $customer = $this->customerRepository->getById($customerId);
             $this->accountManagementHelper->processUnlockData($customerId);
             $this->customerRepository->save($customer);
             $this->getMessageManager()->addSuccess(__('Customer has been unlocked successfully.'));
         }
     } catch (\Exception $e) {
         $this->messageManager->addError($e->getMessage());
     }
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('customer/index/edit', ['id' => $customerId]);
 }
 /**
  * @return void
  */
 public function testExecuteWithException()
 {
     $customerId = 1;
     $phrase = new \Magento\Framework\Phrase('some error');
     $this->requestMock->expects($this->once())->method('getParam')->with($this->equalTo('customer_id'))->will($this->returnValue($customerId));
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($this->customerDataMock);
     $this->accountManagementHelperMock->expects($this->once())->method('processUnlockData')->with($customerId)->willThrowException(new \Exception($phrase));
     $this->messageManagerMock->expects($this->once())->method('addError');
     $this->controller->execute();
 }
 /**
  * @return void
  */
 public function testCheckIfLocked()
 {
     $customerId = 7;
     $email = '*****@*****.**';
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $customerMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->customerSecure->expects($this->once())->method('isCustomerLocked')->willReturn(true);
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email);
     $this->customerRegistryMock->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customerSecure);
     $this->setExpectedException('\\Magento\\Framework\\Exception\\State\\UserLockedException', __('The account is locked. Please wait and try again or contact %1.', $email));
     $this->helper->checkIfLocked($customerMock);
 }
 /**
  * @return void
  */
 public function testAuthenticate()
 {
     $username = '******';
     $password = '******';
     $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customerModel = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock();
     $customerModel->expects($this->once())->method('updateData')->willReturn($customerModel);
     $this->customerRepository->expects($this->once())->method('get')->with($username)->willReturn($customerData);
     $this->accountManagementHelper->expects($this->once())->method('checkIfLocked')->with($customerData);
     $this->accountManagementHelper->expects($this->once())->method('validatePasswordAndLockStatus')->with($customerData, $password);
     $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel);
     $this->manager->expects($this->exactly(2))->method('dispatch')->withConsecutive(['customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]], ['customer_data_object_login', ['customer' => $customerData]]);
     $this->assertEquals($customerData, $this->accountManagement->authenticate($username, $password));
 }
 /**
  * @return void
  */
 public function testGetRequiredCharacterClassesNumber()
 {
     $requiredCharacterClassesNumber = '4';
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with(AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER)->willReturn($requiredCharacterClassesNumber);
     $this->assertEquals($requiredCharacterClassesNumber, $this->block->getRequiredCharacterClassesNumber());
 }