예제 #1
0
 /**
  * @magentoConfigFixture current_store web/session/use_frontend_sid 1
  */
 public function testSetSessionIdFromParam()
 {
     $this->assertNotEquals('test_id', $this->_model->getSessionId());
     $_GET[$this->_sidResolver->getSessionIdQueryParam($this->_model)] = 'test-id';
     $this->_model->setSessionId($this->_sidResolver->getSid($this->_model));
     $this->assertEquals('test-id', $this->_model->getSessionId());
     /* Use not valid identifier */
     $_GET[$this->_sidResolver->getSessionIdQueryParam($this->_model)] = 'test_id';
     $this->_model->setSessionId($this->_sidResolver->getSid($this->_model));
     $this->assertEquals('test-id', $this->_model->getSessionId());
 }
 /**
  * Get a hash of the session id.
  *
  * @return string|null
  */
 protected function getSafeSessionId()
 {
     if (!$this->safeSessionId) {
         // When there is no session id, safeSessionId will be set to null.
         // This will prevent the method call from getting cached (above
         // check will fail) and cause the session to be rechecked for a
         // session id on successive calls until a session id is retrieved.
         // Allowing this behavior in case a log call happens before the
         // session is started. Some calls may miss the session id but once
         // it is available, it will be retrieved, cached and attached to
         // later log calls.
         $sessionId = $this->session->getSessionId();
         $this->safeSessionId = $sessionId ? hash('sha256', $this->session->getSessionId()) : null;
     }
     return $this->safeSessionId;
 }
예제 #3
0
파일: Redirect.php 프로젝트: nja78/magento2
 /**
  * {@inheritdoc}
  *
  * @param array $arguments
  * @return array
  */
 public function updatePathParams(array $arguments)
 {
     if ($this->_session->getCookieShouldBeReceived() && $this->_sidResolver->getUseSessionInUrl() && $this->_canUseSessionIdInParam) {
         $arguments += ['_query' => [$this->_sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId()]];
     }
     return $arguments;
 }
예제 #4
0
 /**
  * Set redirect into response
  *
  * @param \Magento\Framework\App\ResponseInterface $response
  * @param string $path
  * @param array $arguments
  * @return void
  */
 public function redirect(\Magento\Framework\App\ResponseInterface $response, $path, $arguments = array())
 {
     if ($this->_session->getCookieShouldBeReceived() && $this->_urlBuilder->getUseSession() && $this->_canUseSessionIdInParam) {
         $arguments += array('_query' => array($this->_sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId()));
     }
     $response->setRedirect($this->_urlBuilder->getUrl($path, $arguments));
 }
예제 #5
0
 /**
  * Save block content to cache storage
  *
  * @param string $data
  * @return $this
  */
 protected function _saveCache($data)
 {
     if ($this->getCacheLifetime() === null || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) {
         return false;
     }
     $cacheKey = $this->getCacheKey();
     $data = str_replace($this->_sidResolver->getSessionIdQueryParam($this->_session) . '=' . $this->_session->getSessionId(), $this->_getSidPlaceholder($cacheKey), $data);
     $this->_cache->save($data, $cacheKey, $this->getCacheTags(), $this->getCacheLifetime());
     return $this;
 }
예제 #6
0
 /**
  * Initialization visitor by request
  *
  * Used in event "controller_action_predispatch"
  *
  * @param   \Magento\Framework\Event\Observer $observer
  * @return  \Magento\Customer\Model\Visitor
  */
 public function initByRequest($observer)
 {
     if ($this->skipRequestLogging || $this->isModuleIgnored($observer)) {
         return $this;
     }
     if ($this->session->getVisitorData()) {
         $this->setData($this->session->getVisitorData());
     }
     if (!$this->getId()) {
         $this->setSessionId($this->session->getSessionId());
         $this->save();
         $this->_eventManager->dispatch('visitor_init', array('visitor' => $this));
         $this->session->setVisitorData($this->getData());
     }
     return $this;
 }
예제 #7
0
 /**
  * Initialization visitor by request
  *
  * Used in event "controller_action_predispatch"
  *
  * @param   \Magento\Framework\Event\Observer $observer
  * @return  \Magento\Customer\Model\Visitor
  */
 public function initByRequest($observer)
 {
     if ($this->skipRequestLogging || $this->isModuleIgnored($observer)) {
         return $this;
     }
     if ($this->session->getVisitorData()) {
         $this->setData($this->session->getVisitorData());
     }
     $this->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
     if (!$this->getId()) {
         $this->setSessionId($this->session->getSessionId());
         $this->save();
         $this->_eventManager->dispatch('visitor_init', ['visitor' => $this]);
         $this->session->setVisitorData($this->getData());
     }
     return $this;
 }