Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultjunin committed Nov 19, 2017
1 parent 91a2476 commit 90aa96d
Show file tree
Hide file tree
Showing 7 changed files with 734 additions and 710 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/
composer.lock
tests
30 changes: 30 additions & 0 deletions src/Avatar.php
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;
}

}
93 changes: 93 additions & 0 deletions src/Cache.php
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;
}
}

}
23 changes: 23 additions & 0 deletions src/Error.php
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;
}

}
30 changes: 30 additions & 0 deletions src/Login.php
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;
}

}
40 changes: 40 additions & 0 deletions src/LoginTFA.php
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']);
}
}

}
Loading

0 comments on commit 90aa96d

Please sign in to comment.