Skip to content
Browse files

Zmiany w inicjalizacji sesji

  • Loading branch information...
1 parent a7770dd commit 2bedd4d4af1f5e328204b69132ce55b5db2815f2 @serrg serrg committed May 23, 2012
Showing with 14 additions and 14 deletions.
  1. +14 −14 php/GGAPI.php
View
28 php/GGAPI.php
@@ -104,19 +104,17 @@ public function __construct($client_id, $client_secret) {
*
* @return void
*/
- public function initSession($sessionId = null){
+ public function initSession($sessionId = null) {
if($sessionId !== null){
session_id($sessionId);
}
- elseif(isset($_GET['gg_session_id'])){
- session_id($_GET['gg_session_id']);
- }
session_start();
- if(isset($_GET['code']) && !isset($_SESSION['token_data'])){
+ if(isset($_GET['code']) && $_GET['code'] !== $_SESSION['code']){
$token_data = $this->getAccessToken($_GET['code']);
$_SESSION['token_data'] = $token_data;
+ $_SESSION['code'] = $_GET['code'];
}
if(isset($_SESSION['token_data'])){
@@ -186,9 +184,9 @@ public function getUserLocation($user, $ip = null){
$params = array();
if($ip){
- $params['ip'] = $ip;
+ $params['ip'] = $ip;
}
-
+
return $this->doRequest('GET', $this->scopes['geo'].'/userLocation/'.$this->getUser($user), $params, array($this->getAuthHeader()));
}
/**
@@ -197,14 +195,14 @@ public function getUserLocation($user, $ip = null){
* @return array
*/
public function setUserValue($user, $key, $value, $contentType = 'application/json'){
-
+
$params = array(
'content_type' => $contentType,
'value' => json_encode($value),
);
return $this->doRequest('POST', $this->scopes['storage'].'/userStorage/'.$this->getApp().'/'.$this->getUser($user).'/'.$key, $params, array($this->getAuthHeader()));
- }
+ }
/**
* @desc Pobierz klucz z bazy aplikacji
@@ -259,12 +257,14 @@ public function authorize($scopes, $uri = null){
if(count($diff)){
throw new GGAPIException('Incorrect scope: '.join(' ', $diff));
}
-
+ if($uri == null){
+ $uri = $this->getURI();
+ }
$params = array(
'response_type' => 'code',
'client_id' => $this->client_id,
'scope' => join(' ', $scopes),
- 'redirect_uri' => $uri == null ? $this->getURI() : $uri
+ 'redirect_uri' => $uri,
);
$url = $this->auth['authorize'].'?'.http_build_query($params);
@@ -307,7 +307,7 @@ public function getToken(){
*/
public function hasToken(){
- return $this->access_token !== null;
+ return $this->access_token !== null && $this->refresh_token !== null;
}
/**
* @desc Pobierz token
@@ -428,7 +428,7 @@ private function ggApiRequest($method, $uri, $params = null, $headers = null, $s
$add_headers[] = 'User-Agent: GGAPIPHP v'.self::VERSION.' '.php_uname('n');
$add_headers[] = 'Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7';
$headers = array_merge((array) $headers, $add_headers);
-
+
if(!in_array($method, array('GET','POST','PUT','DELETE')))
throw new GGAPIException('Nieprawidłowa metoda');
@@ -443,7 +443,7 @@ private function ggApiRequest($method, $uri, $params = null, $headers = null, $s
$requestUrl = $this->getRequestURL($method, $uri, $params, $ssl, $responseType);
curl_setopt($ch,CURLOPT_URL, $requestUrl);
-
+
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_HEADER, true);

0 comments on commit 2bedd4d

Please sign in to comment.
Something went wrong with that request. Please try again.