/** * 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; }
/** * @return void */ public function testProcessUnlockData() { $customerId = 1; $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure); $this->customerSecure->expects($this->once())->method('setFailuresNum')->with(0); $this->customerSecure->expects($this->once())->method('setFirstFailure')->with(null); $this->customerSecure->expects($this->once())->method('setLockExpires')->with(null); $this->helper->processUnlockData($customerId); }
/** * 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]); }