This repository has been archived by the owner on Jan 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91a2476
commit 90aa96d
Showing
7 changed files
with
734 additions
and
710 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/ | ||
composer.lock | ||
tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace STAILEUAccounts; | ||
|
||
class Avatar{ | ||
|
||
/** | ||
* @var string $base64 The base64 avatar | ||
*/ | ||
private $base64; | ||
|
||
/** | ||
* @var string $url The avatar url | ||
*/ | ||
private $url; | ||
|
||
public function __construct($base64, $url){ | ||
$this->base64 = $base64; | ||
$this->url = $url; | ||
} | ||
|
||
public function getUrl(){ | ||
return $this->url; | ||
} | ||
|
||
public function getBase64(){ | ||
return $this->base64; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace STAILEUAccounts; | ||
|
||
/** | ||
* STAIL.EU Accounts | ||
* | ||
* The new way to have accounts | ||
* | ||
* @author Thibault JUNIN <spamfree@thibaultjunin.fr> | ||
* @copyright 2015-2017 STAN-TAb Corp. | ||
* @license proprietary | ||
* @link https://stail.eu | ||
* @version 3.0.0 | ||
*/ | ||
class Cache{ | ||
|
||
/** | ||
* @var string $cache The cache path folder | ||
*/ | ||
private $cache = "./.stail_cache"; | ||
|
||
public function __construct($dir = "./.stail_cache"){ | ||
$this->cache = $dir; | ||
if(!file_exists($dir)){ | ||
mkdir($dir); | ||
} | ||
} | ||
|
||
/** | ||
* setCache() | ||
* | ||
* This function set the cache | ||
* | ||
* @param string $type The type of data to save | ||
* @param string $name The name of the file | ||
* @param string $data The data to save | ||
* | ||
* @return void | ||
*/ | ||
public function setCache($type, $name, $data){ | ||
if(!file_exists($this->cache."/".$type)){ | ||
mkdir($this->cache."/".$type); | ||
} | ||
if(file_exists($this->cache."/".$type."/".$name)){ | ||
$last = date("U", filemtime($this->cache."/".$type."/".$name)); | ||
if(intval($last)+300 <= time()){ | ||
unlink($this->cache."/".$type."/".$name); | ||
file_put_contents($this->cache."/".$type."/".$name, $data); | ||
} | ||
}else{ | ||
file_put_contents($this->cache."/".$type."/".$name, $data); | ||
} | ||
} | ||
|
||
/** | ||
* getCache() | ||
* | ||
* This function get the cache | ||
* | ||
* @param string $type The type of data to save | ||
* @param string $name The name of the file | ||
* | ||
* @return string The saved data | ||
*/ | ||
public function getCache($type, $name){ | ||
return file_get_contents($this->cache."/".$type."/".$name); | ||
} | ||
|
||
/** | ||
* isCached() | ||
* | ||
* This function check if a data is cached | ||
* | ||
* @param string $type The type of data to save | ||
* @param string $name The name of the file | ||
* | ||
* @return boolean If the data is cached or not (also if the cache has expired) | ||
*/ | ||
public function isCached($type, $name){ | ||
if(file_exists($this->cache."/".$type."/".$name)){ | ||
$last = date("U", filemtime($this->cache."/".$type."/".$name)); | ||
if(intval($last)+300 <= time()){ | ||
return false; | ||
}else{ | ||
return true; | ||
} | ||
}else{ | ||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace STAILEUAccounts; | ||
|
||
class Error{ | ||
|
||
private $code; | ||
private $message; | ||
|
||
public function __construct($code, $msg){ | ||
$this->code = $code; | ||
$this->message = $msg; | ||
} | ||
|
||
public function getMessage(){ | ||
return $this->message; | ||
} | ||
|
||
public function getCode(){ | ||
return $this->code; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace STAILEUAccounts; | ||
|
||
class Login{ | ||
|
||
private $CSA; | ||
private $tfa; | ||
private $tfa_token; | ||
private $d; | ||
|
||
public function __construct($CSA = null, $tfa = false, $tfa_token = null){ | ||
$this->CSA = $CSA; | ||
$this->tfa = $tfa; | ||
$this->tfa_token = $tfa_token; | ||
} | ||
|
||
public function isUsingTfa(){ | ||
return $this->tfa; | ||
} | ||
|
||
public function getCSAToken(){ | ||
return $this->CSA; | ||
} | ||
|
||
public function getTFAToken(){ | ||
return $this->tfa_token; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace STAILEUAccounts; | ||
|
||
class LoginTFA{ | ||
|
||
private $stail; | ||
private $token; | ||
|
||
public function __construct($stail, $tfa_token){ | ||
if(!($stail instanceof \STAILEUAccounts\STAILEUAccounts)){ | ||
throw new Exception("Incorrect first parameter, it MUST BE an instance of '\STAILEUAccounts\STAILEUAccounts'", 1); | ||
} | ||
$this->stail = $stail; | ||
$this->token = $tfa_token; | ||
} | ||
|
||
public function sendTFACode($code){ | ||
$client = new \GuzzleHttp\Client(); | ||
$res = $client->request('POST', $this->stail->getApiUrl()."/login/tfa", [ | ||
'form_params' => [ | ||
"token" => $this->token, | ||
"code" => $code, | ||
"site_key" => $this->stail->getPrivateKey(), | ||
], | ||
'http_errors' => false, | ||
]); | ||
$json = json_decode($res->getBody(), true); | ||
if($res->getStatusCode() == 200){ | ||
if($json['success']){ | ||
return $json['c-sa']; | ||
}else{ | ||
return new \STAILEUAccounts\Error($res->getStatusCode(), $json['error']); | ||
} | ||
}else{ | ||
return new \STAILEUAccounts\Error($res->getStatusCode(), $json['error']); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.