/** * 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); }
/** * @return string */ public function getHref() { return $this->isLoggedIn() ? $this->_customerHelper->getLogoutUrl() : $this->_customerHelper->getLoginUrl(); }