Skip to content
Snippets Groups Projects
Commit 666019f5 authored by Zoltán's avatar Zoltán
Browse files

netbeans crying...

parent 63a50990
No related branches found
No related tags found
No related merge requests found
......@@ -43,16 +43,18 @@ class AuthSCHClient {
}
public function __destruct() {
if(isset($this->tokens))
if(isset($this->tokens)) {
unset ($this->tokens);
}
}
private function curlExec($urlPart, $data) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::$host . $urlPart);
curl_setopt($ch, CURLOPT_HEADER, 0);
if($urlPart != "oauth2/resource")
if($urlPart != "oauth2/resource") {
curl_setopt($ch, CURLOPT_USERPWD, self::$username . ":" . self::$password);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
......@@ -111,15 +113,16 @@ class AuthSCHClient {
$ch = $this->curlExec("oauth2/token", $data);
$tokens = json_decode($ch);
if($tokens === null || !isset($tokens->access_token) || empty($tokens->access_token))
if($tokens === null || !isset($tokens->access_token) || empty($tokens->access_token)) {
throw new Exception ("invalid token data");
}
$this->tokens->access_token = $tokens->access_token;
}
public function getData() {
$response = @file_get_contents(self::$host . 'api/profile/?access_token=' . $this->tokens->access_token);
if(isset($response) && !empty($response)) {
if(isset($response) && $response !== false && !empty($response)) {
$data = json_decode($response);
if($data !== null) {
return $data;
......@@ -127,8 +130,9 @@ class AuthSCHClient {
throw new Exception('invalid json');
}
} else {
if(isset($_SESSION['tokens']))
if(isset($_SESSION['tokens'])) {
unset ($_SESSION['tokens']);
}
throw new Exception('invalid response');
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment