/**
  * @return void
  */
 public function testExecute()
 {
     $customerId = 7;
     $captchaValue = 'some-value';
     $email = '*****@*****.**';
     $redirectUrl = 'http://magento.com/customer/account/edit/';
     $captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false);
     $captcha->expects($this->once())->method('isRequired')->willReturn(true);
     $captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
     $this->helperMock->expects($this->once())->method('getCaptcha')->with(\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captcha);
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]);
     $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, \Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captchaValue);
     $customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', [], [], '', false);
     $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomer')->willReturn($customerDataMock);
     $this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId);
     $this->authenticationMock->expects($this->once())->method('isLocked')->with($customerId)->willReturn(true);
     $this->customerSessionMock->expects($this->once())->method('logout');
     $this->customerSessionMock->expects($this->once())->method('start');
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email);
     $message = __('The account is locked. Please wait and try again or contact %1.', $email);
     $this->messageManagerMock->expects($this->exactly(2))->method('addError')->withConsecutive([$message], [__('Incorrect CAPTCHA')]);
     $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
     $this->redirectMock->expects($this->once())->method('redirect')->with($response, '*/*/edit')->willReturn($redirectUrl);
     $this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
 }
 /**
  * Reset Attempts For Frontend
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Magento\Captcha\Observer\ResetAttemptForFrontendObserver
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $email = $observer->getEmail();
     $captchaModel = $this->helper->getCaptcha(self::FORM_ID);
     $captchaModel->setShowCaptchaInSession(false);
     return $this->resLogFactory->create()->deleteUserAttempts($email);
 }
예제 #3
0
 /**
  * @param \Magento\Customer\Controller\Ajax\Login $subject
  * @param \Closure $proceed
  * @return $this
  * @throws \Zend_Json_Exception
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundExecute(\Magento\Customer\Controller\Ajax\Login $subject, \Closure $proceed)
 {
     $captchaFormIdField = 'captcha_form_id';
     $captchaInputName = 'captcha_string';
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $subject->getRequest();
     $loginParams = [];
     $content = $request->getContent();
     if ($content) {
         $loginParams = \Zend_Json::decode($content);
     }
     $username = isset($loginParams['username']) ? $loginParams['username'] : null;
     $captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
     $loginFormId = isset($loginParams[$captchaFormIdField]) ? $loginParams[$captchaFormIdField] : null;
     foreach ($this->formIds as $formId) {
         $captchaModel = $this->helper->getCaptcha($formId);
         if ($captchaModel->isRequired($username) && !in_array($loginFormId, $this->formIds)) {
             $resultJson = $this->resultJsonFactory->create();
             return $resultJson->setData(['errors' => true, 'message' => __('Provided form does not exist')]);
         }
         if ($formId == $loginFormId) {
             $captchaModel->logAttempt($username);
             if (!$captchaModel->isCorrect($captchaString)) {
                 $this->sessionManager->setUsername($username);
                 /** @var \Magento\Framework\Controller\Result\Json $resultJson */
                 $resultJson = $this->resultJsonFactory->create();
                 return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
             }
         }
     }
     return $proceed();
 }
 /**
  * @return void
  */
 public function testExecute()
 {
     $formId = 'user_login';
     $login = '******';
     $loginParams = ['username' => $login];
     $customerId = 7;
     $redirectUrl = 'http://magento.com/customer/account/login/';
     $captchaValue = 'some-value';
     $captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false);
     $captcha->expects($this->once())->method('isRequired')->with($login)->willReturn(true);
     $captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
     $captcha->expects($this->once())->method('logAttempt')->with($login);
     $this->helperMock->expects($this->once())->method('getCaptcha')->with($formId)->willReturn($captcha);
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $response->expects($this->once())->method('setRedirect')->with($redirectUrl);
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $request->expects($this->any())->method('getPost')->with('login')->willReturn($loginParams);
     $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, $formId)->willReturn($captchaValue);
     $customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', ['getId'], [], '', false);
     $customerDataMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->customerRepositoryMock->expects($this->once())->method('get')->with($login)->willReturn($customerDataMock);
     $this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('Incorrect CAPTCHA'));
     $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
     $this->customerSessionMock->expects($this->once())->method('setUsername')->with($login);
     $this->customerSessionMock->expects($this->once())->method('getBeforeAuthUrl')->willReturn(false);
     $this->customerUrlMock->expects($this->once())->method('getLoginUrl')->willReturn($redirectUrl);
     $this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
 }
 /**
  * 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;
 }
예제 #6
0
 /**
  * Renders captcha HTML (if required)
  *
  * @return string
  */
 protected function _toHtml()
 {
     $blockPath = $this->_captchaData->getCaptcha($this->getFormId())->getBlockName();
     $block = $this->getLayout()->createBlock($blockPath);
     $block->setData($this->getData());
     return $block->toHtml();
 }
예제 #7
0
파일: Font.php 프로젝트: aiesh/magento2
 /**
  * Get options for font selection field
  *
  * @return array
  */
 public function toOptionArray()
 {
     $optionArray = array();
     foreach ($this->_captchaData->getFonts() as $fontName => $fontData) {
         $optionArray[] = array('label' => $fontData['label'], 'value' => $fontName);
     }
     return $optionArray;
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $formId = $this->_request->getPost('formId');
     $captchaModel = $this->captchaHelper->getCaptcha($formId);
     $block = $this->_view->getLayout()->createBlock($captchaModel->getBlockName());
     $block->setFormId($formId)->setIsAjax(true)->toHtml();
     $this->_response->representJson(json_encode(array('imgSrc' => $captchaModel->getImgSrc())));
     $this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
 }
 /**
  * Delete Expired Captcha Images for specific website
  *
  * @param \Magento\Captcha\Helper\Data $helper
  * @param \Magento\Store\Model\Website|null $website
  * @param \Magento\Store\Model\Store|null $store
  * @return void
  */
 protected function _deleteExpiredImagesForWebsite(\Magento\Captcha\Helper\Data $helper, \Magento\Store\Model\Website $website = null, \Magento\Store\Model\Store $store = null)
 {
     $expire = time() - $helper->getConfig('timeout', $store) * 60;
     $imageDirectory = $this->_mediaDirectory->getRelativePath($helper->getImgDir($website));
     foreach ($this->_mediaDirectory->read($imageDirectory) as $filePath) {
         if ($this->_mediaDirectory->isFile($filePath) && pathinfo($filePath, PATHINFO_EXTENSION) == 'png' && $this->_mediaDirectory->stat($filePath)['mtime'] < $expire) {
             $this->_mediaDirectory->delete($filePath);
         }
     }
 }
 /**
  * Check Captcha On User Login Backend Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @throws \Magento\Framework\Exception\Plugin\AuthenticationException
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'backend_login';
     $captchaModel = $this->_helper->getCaptcha($formId);
     $login = $observer->getEvent()->getUsername();
     if ($captchaModel->isRequired($login)) {
         if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($this->_request, $formId))) {
             $captchaModel->logAttempt($login);
             throw new PluginAuthenticationException(__('Incorrect CAPTCHA.'));
         }
     }
     $captchaModel->logAttempt($login);
     return $this;
 }
예제 #11
0
 /**
  * @param \Magento\Quote\Model\AddressAdditionalDataProcessor $subject
  * @param \Magento\Quote\Api\Data\AddressAdditionalDataInterface $additionalData
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  * @throws \Magento\Framework\Exception\InputException
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeProcess(\Magento\Quote\Model\AddressAdditionalDataProcessor $subject, \Magento\Quote\Api\Data\AddressAdditionalDataInterface $additionalData)
 {
     $formId = $additionalData->getExtensionAttributes()->getCaptchaFormId();
     $captchaText = $additionalData->getExtensionAttributes()->getCaptchaString();
     if ($formId !== null && !in_array($formId, $this->formIds)) {
         throw new NoSuchEntityException(__('Provided form does not exist'));
     }
     $captchaModel = $this->captchaHelper->getCaptcha($formId);
     if ($captchaModel->isRequired()) {
         if (!$captchaModel->isCorrect($captchaText)) {
             throw new InputException(__('Incorrect CAPTCHA'));
         }
     }
 }
 /**
  * Check CAPTCHA on Contact Us page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'contact_us';
     $captcha = $this->_helper->getCaptcha($formId);
     if ($captcha->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
             $this->messageManager->addError(__('Incorrect CAPTCHA.'));
             $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->redirect->redirect($controller->getResponse(), 'contact/index/index');
         }
     }
 }
 public function testCheckContactUsFormDoesNotCheckCaptchaWhenItIsNotRequired()
 {
     $this->helperMock->expects($this->any())->method('getCaptcha')->with('contact_us')->willReturn($this->captchaMock);
     $this->captchaMock->expects($this->any())->method('isRequired')->willReturn(false);
     $this->captchaMock->expects($this->never())->method('isCorrect');
     $this->checkContactUsFormObserver->execute(new \Magento\Framework\Event\Observer());
 }
 /**
  * Check captcha on user login page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @throws NoSuchEntityException
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'user_login';
     $captchaModel = $this->_helper->getCaptcha($formId);
     $controller = $observer->getControllerAction();
     $loginParams = $controller->getRequest()->getPost('login');
     $login = is_array($loginParams) && 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->getAuthentication()->processAuthenticationFailure($customer->getId());
             } 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);
     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;
 }
 /**
  * Check Captcha On User Login Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'user_create';
     $captchaModel = $this->_helper->getCaptcha($formId);
     if ($captchaModel->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
             $this->messageManager->addError(__('Incorrect CAPTCHA'));
             $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->_session->setCustomerFormData($controller->getRequest()->getPostValue());
             $url = $this->_urlManager->getUrl('*/*/create', ['_nosecret' => true]);
             $controller->getResponse()->setRedirect($this->redirect->error($url));
         }
     }
     return $this;
 }
 /**
  * Check Captcha On Checkout as Guest Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'guest_checkout';
     $captchaModel = $this->_helper->getCaptcha($formId);
     $checkoutMethod = $this->_typeOnepage->getQuote()->getCheckoutMethod();
     if ($checkoutMethod == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) {
         if ($captchaModel->isRequired()) {
             $controller = $observer->getControllerAction();
             if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
                 $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
                 $result = ['error' => 1, 'message' => __('Incorrect CAPTCHA')];
                 $controller->getResponse()->representJson($this->jsonHelper->jsonEncode($result));
             }
         }
     }
     return $this;
 }
예제 #18
0
파일: Index.php 프로젝트: nja78/magento2
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $formId = $this->_request->getPost('formId');
     if (null === $formId) {
         try {
             $params = \Zend_Json::decode($this->_request->getContent());
             $formId = isset($params['formId']) ? $params['formId'] : null;
         } catch (\Zend_Json_Exception $exception) {
             $formId = null;
         }
     }
     $captchaModel = $this->captchaHelper->getCaptcha($formId);
     $captchaModel->generate();
     $block = $this->_view->getLayout()->createBlock($captchaModel->getBlockName());
     $block->setFormId($formId)->setIsAjax(true)->toHtml();
     $this->_response->representJson(json_encode(['imgSrc' => $captchaModel->getImgSrc()]));
     $this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
 }
 /**
  * Check Captcha On User Login Backend Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @throws \Magento\Framework\Exception\Plugin\AuthenticationException
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'backend_forgotpassword';
     $captchaModel = $this->_helper->getCaptcha($formId);
     $controller = $observer->getControllerAction();
     $email = (string) $observer->getControllerAction()->getRequest()->getParam('email');
     $params = $observer->getControllerAction()->getRequest()->getParams();
     if (!empty($email) && !empty($params)) {
         if ($captchaModel->isRequired()) {
             if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
                 $this->_session->setEmail((string) $controller->getRequest()->getPost('email'));
                 $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
                 $this->messageManager->addError(__('Incorrect CAPTCHA'));
                 $controller->getResponse()->setRedirect($controller->getUrl('*/*/forgotpassword', ['_nosecret' => true]));
             }
         }
     }
     return $this;
 }
예제 #20
0
 /**
  * @dataProvider getExpiredImages
  */
 public function testDeleteExpiredImages($website, $isFile, $filename, $mTime, $timeout, $mustDelete)
 {
     $this->_storeManager->expects($this->once())->method('getWebsites')->will($this->returnValue(isset($website) ? [$website] : []));
     if (isset($website)) {
         $this->_helper->expects($this->once())->method('getConfig')->with($this->equalTo('timeout'), new \PHPUnit_Framework_Constraint_IsIdentical($website->getDefaultStore()))->will($this->returnValue($timeout));
     } else {
         $this->_helper->expects($this->never())->method('getConfig');
     }
     $this->_adminHelper->expects($this->once())->method('getConfig')->with($this->equalTo('timeout'), new \PHPUnit_Framework_Constraint_IsNull())->will($this->returnValue($timeout));
     $timesToCall = isset($website) ? 2 : 1;
     $this->_directory->expects($this->exactly($timesToCall))->method('read')->will($this->returnValue([$filename]));
     $this->_directory->expects($this->exactly($timesToCall))->method('isFile')->will($this->returnValue($isFile));
     $this->_directory->expects($this->any())->method('stat')->will($this->returnValue(['mtime' => $mTime]));
     if ($mustDelete) {
         $this->_directory->expects($this->exactly($timesToCall))->method('delete')->with($filename);
     } else {
         $this->_directory->expects($this->never())->method('delete');
     }
     $this->_model->deleteExpiredImages();
 }
 /**
  * Check Captcha On User Login Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'user_login';
     $captchaModel = $this->_helper->getCaptcha($formId);
     $controller = $observer->getControllerAction();
     $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)) {
             $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);
     return $this;
 }
예제 #22
0
 /**
  * @param \Magento\Customer\Controller\Ajax\Login $subject
  * @param callable $proceed
  * @return \Magento\Framework\Controller\ResultInterface
  * @throws \Zend_Json_Exception
  */
 public function aroundExecute(\Magento\Customer\Controller\Ajax\Login $subject, \Closure $proceed)
 {
     $loginFormId = 'user_login';
     $captchaInputName = 'captcha_string';
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $subject->getRequest();
     /** @var \Magento\Captcha\Model\ModelInterface $captchaModel */
     $captchaModel = $this->helper->getCaptcha($loginFormId);
     $loginParams = \Zend_Json::decode($request->getContent());
     $username = isset($loginParams['username']) ? $loginParams['username'] : null;
     $captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
     if ($captchaModel->isRequired($username)) {
         $captchaModel->logAttempt($username);
         if (!$captchaModel->isCorrect($captchaString)) {
             $this->sessionManager->setUsername($username);
             /** @var \Magento\Framework\Controller\Result\Json $resultJson */
             $resultJson = $this->resultJsonFactory->create();
             return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
         }
     }
     return $proceed();
 }
예제 #23
0
 /**
  * Retrieve list of forms where captcha must be shown
  *
  * For frontend this list is based on current website
  *
  * @return array
  */
 protected function _getTargetForms()
 {
     $formsString = (string) $this->_captchaData->getConfig('forms');
     return explode(',', $formsString);
 }
예제 #24
0
 /**
  * @covers \Magento\Captcha\Model\DefaultModel::getImgUrl
  * @covers \Magento\Captcha\Helper\Data::getImgUrl
  */
 public function testGetImgUrl()
 {
     $this->assertEquals($this->helper->getImgUrl(), 'http://localhost/pub/media/captcha/base/');
 }
예제 #25
0
 /**
  * @param \Magento\Framework\App\Helper\Context $context
  * @param \Magento\Store\Model\StoreManager $storeManager
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Captcha\Model\CaptchaFactory $factory
  * @param \Magento\Backend\App\ConfigInterface $backendConfig
  */
 public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManager $storeManager, \Magento\Framework\Filesystem $filesystem, \Magento\Captcha\Model\CaptchaFactory $factory, \Magento\Backend\App\ConfigInterface $backendConfig)
 {
     $this->_backendConfig = $backendConfig;
     parent::__construct($context, $storeManager, $filesystem, $factory);
 }
예제 #26
0
 /**
  * Return captcha model for specified form
  *
  * @param string $formId
  * @return \Magento\Captcha\Model\CaptchaInterface
  */
 protected function getCaptchaModel($formId)
 {
     return $this->captchaData->getCaptcha($formId);
 }
예제 #27
0
 /**
  * Returns captcha model
  *
  * @return \Magento\Captcha\Model\ModelInterface
  */
 public function getCaptchaModel()
 {
     return $this->_captchaData->getCaptcha($this->getFormId());
 }