/** * Authenticate user * * @param \Magento\Framework\App\ActionInterface $subject * @param RequestInterface $request * @return void */ public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request) { $loginUrl = $this->customerHelper->getLoginUrl(); if (!$this->customerSession->authenticate($subject, $loginUrl)) { $subject->getActionFlag()->set('', $subject::FLAG_NO_DISPATCH, true); } }
/** * Retrieve back url * * @return string */ public function getBackUrl() { $url = $this->getData('back_url'); if (is_null($url)) { $url = $this->_customerHelper->getLoginUrl(); } return $url; }
/** * Check Captcha On User Login Page * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function checkUserLogin($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->_getCaptchaString($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->_customerData->getLoginUrl(); $controller->getResponse()->setRedirect($url); } } $captchaModel->logAttempt($login); return $this; }
/** * Define and return target URL after logging in * * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _loginPostRedirect() { $lastCustomerId = $this->_getSession()->getLastCustomerId(); if (isset($lastCustomerId) && $this->_getSession()->isLoggedIn() && $lastCustomerId != $this->_getSession()->getId()) { $this->_getSession()->unsBeforeAuthUrl()->setLastCustomerId($this->_getSession()->getId()); } if (!$this->_getSession()->getBeforeAuthUrl() || $this->_getSession()->getBeforeAuthUrl() == $this->_storeManager->getStore()->getBaseUrl()) { // Set default URL to redirect customer to $this->_getSession()->setBeforeAuthUrl($this->_customerHelperData->getAccountUrl()); // Redirect customer to the last page visited after logging in if ($this->_getSession()->isLoggedIn()) { if (!$this->_scopeConfig->isSetFlag(\Magento\Customer\Helper\Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { $referer = $this->getRequest()->getParam(\Magento\Customer\Helper\Data::REFERER_QUERY_PARAM_NAME); if ($referer) { $referer = $this->coreHelperData->urlDecode($referer); if ($this->_url->isOwnOriginUrl()) { $this->_getSession()->setBeforeAuthUrl($referer); } } } elseif ($this->_getSession()->getAfterAuthUrl()) { $this->_getSession()->setBeforeAuthUrl($this->_getSession()->getAfterAuthUrl(true)); } } else { $this->_getSession()->setBeforeAuthUrl($this->_customerHelperData->getLoginUrl()); } } elseif ($this->_getSession()->getBeforeAuthUrl() == $this->_customerHelperData->getLogoutUrl()) { $this->_getSession()->setBeforeAuthUrl($this->_customerHelperData->getDashboardUrl()); } else { if (!$this->_getSession()->getAfterAuthUrl()) { $this->_getSession()->setAfterAuthUrl($this->_getSession()->getBeforeAuthUrl()); } if ($this->_getSession()->isLoggedIn()) { $this->_getSession()->setBeforeAuthUrl($this->_getSession()->getAfterAuthUrl(true)); } } return $this->_getSession()->getBeforeAuthUrl(true); }
/** * 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->_customerHelper->getLoginUrl(), array('context' => 'checkout'))); }
/** * @return string */ public function getHref() { return $this->isLoggedIn() ? $this->_customerHelper->getLogoutUrl() : $this->_customerHelper->getLoginUrl(); }