/** * Authenticate user * * @param \Magento\Framework\App\ActionInterface $subject * @param RequestInterface $request * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request) { $loginUrl = $this->customerUrl->getLoginUrl(); if (!$this->customerSession->authenticate($loginUrl)) { $subject->getActionFlag()->set('', $subject::FLAG_NO_DISPATCH, true); } }
/** * Retrieve back url * * @return string */ public function getBackUrl() { $url = $this->getData('back_url'); if ($url === null) { $url = $this->_customerUrl->getLoginUrl(); } return $url; }
/** * Check customer authentication * * @param RequestInterface $request * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\App\ResponseInterface */ public function dispatch(RequestInterface $request) { $loginUrl = $this->customerUrl->getLoginUrl(); if (!$this->customerSession->authenticate($loginUrl)) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); } if (!$this->config->useVault()) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('noRoute'); return $resultRedirect; } return parent::dispatch($request); }
/** * 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; }
/** * Prepare redirect URL * * @return void */ protected function prepareRedirectUrl() { $baseUrl = $this->storeManager->getStore()->getBaseUrl(); $url = $this->session->getBeforeAuthUrl(); if (!$url) { $url = $baseUrl; } switch ($url) { case $baseUrl: if ($this->session->isLoggedIn()) { $this->processLoggedCustomer(); } else { $this->applyRedirect($this->customerUrl->getLoginUrl()); } break; case $this->customerUrl->getLogoutUrl(): $this->applyRedirect($this->customerUrl->getDashboardUrl()); break; default: if (!$this->session->getAfterAuthUrl()) { $this->session->setAfterAuthUrl($this->session->getBeforeAuthUrl()); } if ($this->session->isLoggedIn()) { $this->applyRedirect($this->session->getAfterAuthUrl(true)); } break; } }
/** * 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; }
/** * Redirect to login page * * @return void */ public function redirectLogin() { $this->_actionFlag->set('', 'no-dispatch', true); $this->_customerSession->setBeforeAuthUrl($this->_redirect->getRefererUrl()); $this->getResponse()->setRedirect($this->_urlHelper->addRequestParam($this->_customerUrl->getLoginUrl(), ['context' => 'checkout'])); }
/** * @return string */ public function getHref() { return $this->isLoggedIn() ? $this->_customerUrl->getLogoutUrl() : $this->_customerUrl->getLoginUrl(); }
/** * Get login URL * * @return string */ public function getLoginUrl() { return $this->customerUrl->getLoginUrl(); }