Beispiel #1
0
 /**
  * Update the cookie information.
  */
 protected function updateCookie()
 {
     printDebug("We manage the cookie...");
     if (isset($this->visitorInfo['referer_type']) && $this->visitorInfo['referer_type'] != Piwik_Common::REFERER_TYPE_DIRECT_ENTRY) {
         // if the setting is set to use only the first referer,
         // we don't update the cookie referer values if they are already set
         if (!Piwik_Tracker_Config::getInstance()->Tracker['use_first_referer_to_determine_goal_referer'] || $this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_TYPE) == false) {
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_TYPE, $this->visitorInfo['referer_type']);
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_NAME, $this->visitorInfo['referer_name']);
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_KEYWORD, $this->visitorInfo['referer_keyword']);
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_ID_VISIT, $this->visitorInfo['idvisit']);
             $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_REFERER_TIMESTAMP, $this->getCurrentTimestamp());
         }
     }
     // idcookie has been generated in handleNewVisit or we simply propagate the old value
     $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_IDVISITOR, $this->visitorInfo['visitor_idcookie']);
     // the last action timestamp is the current timestamp
     $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_TIMESTAMP_LAST_ACTION, $this->visitorInfo['visit_last_action_time']);
     // the first action timestamp is the timestamp of the first action of the current visit
     $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_TIMESTAMP_FIRST_ACTION, $this->visitorInfo['visit_first_action_time']);
     // the idvisit has been generated by mysql in handleNewVisit or simply propagated here
     $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_ID_VISIT, $this->visitorInfo['idvisit']);
     // the last action ID is the current exit idaction
     if (isset($this->visitorInfo['visit_exit_idaction'])) {
         $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_ID_LAST_ACTION, $this->visitorInfo['visit_exit_idaction']);
     }
     // for a new visit, we flag the visit with visitor_returning
     if (isset($this->visitorInfo['visitor_returning'])) {
         $this->cookie->set(Piwik_Tracker::COOKIE_INDEX_VISITOR_RETURNING, $this->visitorInfo['visitor_returning']);
     }
     $this->cookie->save();
 }
 protected function authenticateAndRedirect($login, $md5Password, $urlToRedirect)
 {
     $tokenAuth = Piwik_UsersManager_API::getTokenAuth($login, $md5Password);
     $auth = Zend_Registry::get('auth');
     $auth->setLogin($login);
     $auth->setTokenAuth($tokenAuth);
     $authResult = $auth->authenticate();
     if ($authResult->isValid()) {
         $authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
         $authCookieExpiry = time() + Zend_Registry::get('config')->General->login_cookie_expire;
         $cookie = new Piwik_Cookie($authCookieName, $authCookieExpiry);
         $cookie->set('login', $login);
         $cookie->set('token_auth', $authResult->getTokenAuth());
         $cookie->save();
         $urlToRedirect = htmlspecialchars_decode($urlToRedirect);
         Piwik_Url::redirectToUrl($urlToRedirect);
     }
     return false;
 }
Beispiel #3
0
 /**
  * Update the cookie information.
  */
 protected function setThirdPartyCookie()
 {
     if (!$this->shouldUseThirdPartyCookie()) {
         return;
     }
     printDebug("We manage the cookie...");
     // idcookie has been generated in handleNewVisit or we simply propagate the old value
     $this->cookie->set(0, bin2hex($this->visitorInfo['idvisitor']));
     $this->cookie->save();
 }
Beispiel #4
0
 /**
  * Authenticate user and initializes the session.
  * Listens to Login.initSession hook.
  *
  * @param Piwik_Event_Notification $notification  notification object
  * @throws Exception
  */
 function initSession($notification)
 {
     $info = $notification->getNotificationObject();
     $login = $info['login'];
     $md5Password = $info['md5Password'];
     $rememberMe = $info['rememberMe'];
     $tokenAuth = Piwik_UsersManager_API::getInstance()->getTokenAuth($login, $md5Password);
     $auth = Zend_Registry::get('auth');
     $auth->setLogin($login);
     $auth->setTokenAuth($tokenAuth);
     $authResult = $auth->authenticate();
     $authCookieName = Piwik_Config::getInstance()->General['login_cookie_name'];
     $authCookieExpiry = $rememberMe ? time() + Piwik_Config::getInstance()->General['login_cookie_expire'] : 0;
     $authCookiePath = Piwik_Config::getInstance()->General['login_cookie_path'];
     $cookie = new Piwik_Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
     if (!$authResult->isValid()) {
         $cookie->delete();
         throw new Exception(Piwik_Translate('Login_LoginPasswordNotCorrect'));
     }
     $cookie->set('login', $login);
     $cookie->set('token_auth', $auth->getHashTokenAuth($login, $authResult->getTokenAuth()));
     $cookie->setSecure(Piwik::isHttps());
     $cookie->setHttpOnly(true);
     $cookie->save();
     @Piwik_Session::regenerateId();
     // remove password reset entry if it exists
     self::removePasswordResetInfo($login);
 }
 /**
  * Set the language for the session
  *
  * @param string $languageCode ISO language code
  */
 public static function setLanguageForSession($languageCode)
 {
     if (!Piwik_LanguagesManager_API::getInstance()->isLanguageAvailable($languageCode)) {
         return false;
     }
     $cookieName = Zend_Registry::get('config')->General->language_cookie_name;
     $cookie = new Piwik_Cookie($cookieName, 0);
     $cookie->set('language', $languageCode);
     $cookie->save();
 }
Beispiel #6
0
 /**
  * Authenticate user and password.  Redirect if successful.
  *
  * @param string $login (user name)
  * @param string $md5Password (md5 hash of password)
  * @param string $urlToRedirect (URL to redirect to, if successfully authenticated)
  * @return string (failure message if unable to authenticate)
  */
 protected function authenticateAndRedirect($login, $md5Password, $urlToRedirect)
 {
     $tokenAuth = Piwik_UsersManager_API::getInstance()->getTokenAuth($login, $md5Password);
     $auth = Zend_Registry::get('auth');
     $auth->setLogin($login);
     $auth->setTokenAuth($tokenAuth);
     $authResult = $auth->authenticate();
     if (!$authResult->isValid()) {
         return Piwik_Translate('Login_LoginPasswordNotCorrect');
     }
     $authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
     $authCookieExpiry = time() + Zend_Registry::get('config')->General->login_cookie_expire;
     $authCookiePath = Zend_Registry::get('config')->General->login_cookie_path;
     $cookie = new Piwik_Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
     $cookie->set('login', $login);
     $cookie->set('token_auth', $authResult->getTokenAuth());
     $cookie->save();
     Zend_Session::regenerateId();
     Piwik_Url::redirectToUrl($urlToRedirect);
 }