Example #1
0
 /**
  * Authenticate controller action by login customer
  *
  * @param   \Magento\Framework\App\Action\Action $action
  * @param   bool|null $loginUrl
  * @return  bool
  */
 public function authenticate(\Magento\Framework\App\Action\Action $action, $loginUrl = null)
 {
     if ($this->isLoggedIn()) {
         return true;
     }
     $this->setBeforeAuthUrl($this->_createUrl()->getUrl('*/*/*', array('_current' => true)));
     if (isset($loginUrl)) {
         $action->getResponse()->setRedirect($loginUrl);
     } else {
         $arguments = $this->_customerData->getLoginUrlParams();
         if ($this->_session->getCookieShouldBeReceived() && $this->_createUrl()->getUseSession()) {
             $arguments += array('_query' => array($this->sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId()));
         }
         $action->getResponse()->setRedirect($this->_createUrl()->getUrl(\Magento\Customer\Helper\Data::ROUTE_ACCOUNT_LOGIN, $arguments));
     }
     return false;
 }