/** * Resets the session, if access token exists, tries to use it * * @return bool */ public function reset() { if (!$this->AccessToken && !empty($_SESSION[self::ODR_TOKEN_SESSION])) { $this->AccessToken = $_SESSION[self::ODR_TOKEN_SESSION]; } if (strpos($this->User, 'public$') !== 0) { return $this->parseError('Vul de API key als gebruikersnaam in en de API secret als wachtwoord.'); } // @codeCoverageIgnoreStart if (!$this->odr) { $config = array('api_key' => $this->User, 'api_secret' => $this->Password, 'url' => $this->Testmode ? self::URL_TEST : self::URL_LIVE); $this->odr = new Api_Odr($config); } // @codeCoverageIgnoreEnd if ($this->AccessToken && is_string($this->AccessToken)) { try { $this->odr->setHeader('X-Access-Token', $this->AccessToken); $meResult = $this->odr->getMe()->getResult(); if ($meResult['status'] === Api_Odr::STATUS_ERROR) { if (!empty($_SESSION[self::ODR_TOKEN_SESSION])) { unset($_SESSION[self::ODR_TOKEN_SESSION]); } $this->AccessToken = false; $this->odr->setHeader('X-Access-Token', null); } } catch (Api_Odr_Exception $e) { if (!empty($_SESSION[self::ODR_TOKEN_SESSION])) { unset($_SESSION[self::ODR_TOKEN_SESSION]); } $this->AccessToken = false; $this->odr->setHeader('X-Access-Token', null); } if ($this->AccessToken) { return true; } } try { $loginResult = $this->odr->login()->getResult(); if ($loginResult['status'] === Api_Odr::STATUS_ERROR) { return $this->parseError($loginResult['response'], $loginResult['code']); } $this->AccessToken = $loginResult['response']['token']; $_SESSION[self::ODR_TOKEN_SESSION] = $this->AccessToken; } catch (Api_Odr_Exception $e) { $this->Error[] = $e->getMessage(); return false; } return true; }