[enh] formatting
This commit is contained in:
parent
afbed13686
commit
a1a49955c2
|
@ -12,19 +12,15 @@ interface Alternc_Api_Auth_Interface {
|
||||||
*/
|
*/
|
||||||
function __construct($service);
|
function __construct($service);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* auth takes options specific to the auth itself
|
* auth takes options specific to the auth itself
|
||||||
* returns an Alternc_Api_Token object
|
* returns an Alternc_Api_Token object
|
||||||
*/
|
*/
|
||||||
function auth($options);
|
function auth($options);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* instructions on how to use this Auth class
|
* instructions on how to use this Auth class
|
||||||
* @return array("fields" => array("fields to send, required or not"), "description" => "description of this auth")
|
* @return array("fields" => array("fields to send, required or not"), "description" => "description of this auth")
|
||||||
*/
|
*/
|
||||||
function instructions();
|
function instructions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
class Alternc_Api_Auth_Login implements Alternc_Api_Auth_Interface {
|
class Alternc_Api_Auth_Login implements Alternc_Api_Auth_Interface {
|
||||||
|
|
||||||
|
|
||||||
private $db; // PDO object
|
private $db; // PDO object
|
||||||
|
|
||||||
const ERR_INVALID_ARGUMENT = 1111201;
|
const ERR_INVALID_ARGUMENT = 1111201;
|
||||||
|
@ -16,15 +15,13 @@ class Alternc_Api_Auth_Login implements Alternc_Api_Auth_Interface {
|
||||||
* @param $service an Alternc_Api_Service object
|
* @param $service an Alternc_Api_Service object
|
||||||
* @return create the object
|
* @return create the object
|
||||||
*/
|
*/
|
||||||
function __constructor($service) {
|
function __construct($service) {
|
||||||
|
|
||||||
if (!($service instanceof Alternc_Api_Service))
|
if (!($service instanceof Alternc_Api_Service))
|
||||||
throw new \Exception("Invalid argument (service)", ERR_INVALID_ARGUMENT);
|
throw new \Exception("Invalid argument (service)", ERR_INVALID_ARGUMENT);
|
||||||
|
|
||||||
$this->db = $service->getDb();
|
$this->db = $service->getDb();
|
||||||
|
}
|
||||||
} // __construct
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticate a user
|
* Authenticate a user
|
||||||
|
@ -54,12 +51,10 @@ class Alternc_Api_Auth_Login implements Alternc_Api_Auth_Interface {
|
||||||
return new Alternc_Api_Response(array("code" => ERR_DISABLED_ACCOUNT, "message" => "Account is disabled"));
|
return new Alternc_Api_Response(array("code" => ERR_DISABLED_ACCOUNT, "message" => "Account is disabled"));
|
||||||
|
|
||||||
return Alternc_Api_Token::tokenGenerate(
|
return Alternc_Api_Token::tokenGenerate(
|
||||||
array("uid"=>$me->uid, "isAdmin"=>($me->su!=0) ),
|
array("uid" => $me->uid, "isAdmin" => ($me->su != 0)), $this->db
|
||||||
$this->db
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* instructions on how to use this Auth class
|
* instructions on how to use this Auth class
|
||||||
* @return array("fields" => array("fields to send, required or not"), "description" => "description of this auth")
|
* @return array("fields" => array("fields to send, required or not"), "description" => "description of this auth")
|
||||||
|
@ -70,6 +65,7 @@ class Alternc_Api_Auth_Login implements Alternc_Api_Auth_Interface {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // class Alternc_Api_Auth_Login
|
// class Alternc_Api_Auth_Login
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
class Alternc_Api_Auth_Sharedsecret implements Alternc_Api_Auth_Interface {
|
class Alternc_Api_Auth_Sharedsecret implements Alternc_Api_Auth_Interface {
|
||||||
|
|
||||||
|
|
||||||
private $db; // PDO object
|
private $db; // PDO object
|
||||||
|
|
||||||
const ERR_INVALID_ARGUMENT = 1111801;
|
const ERR_INVALID_ARGUMENT = 1111801;
|
||||||
|
@ -27,9 +26,9 @@ class Alternc_Api_Auth_Sharedsecret implements Alternc_Api_Auth_Interface {
|
||||||
throw new \Exception("Invalid argument (service)", ERR_INVALID_ARGUMENT);
|
throw new \Exception("Invalid argument (service)", ERR_INVALID_ARGUMENT);
|
||||||
|
|
||||||
$this->db = $service->getDb();
|
$this->db = $service->getDb();
|
||||||
|
}
|
||||||
|
|
||||||
} // __construct
|
// __construct
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticate a user
|
* Authenticate a user
|
||||||
|
@ -63,12 +62,10 @@ class Alternc_Api_Auth_Sharedsecret implements Alternc_Api_Auth_Interface {
|
||||||
return new Alternc_Api_Response(array("code" => self::ERR_DISABLED_ACCOUNT, "message" => "Account is disabled"));
|
return new Alternc_Api_Response(array("code" => self::ERR_DISABLED_ACCOUNT, "message" => "Account is disabled"));
|
||||||
|
|
||||||
return Alternc_Api_Token::tokenGenerate(
|
return Alternc_Api_Token::tokenGenerate(
|
||||||
array("uid"=>(int)$me->uid, "isAdmin"=>($me->su!=0) ),
|
array("uid" => (int) $me->uid, "isAdmin" => ($me->su != 0)), $this->db
|
||||||
$this->db
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* instructions on how to use this Auth class
|
* instructions on how to use this Auth class
|
||||||
* @return array("fields" => array("fields to send, required or not"), "description" => "description of this auth")
|
* @return array("fields" => array("fields to send, required or not"), "description" => "description of this auth")
|
||||||
|
@ -79,6 +76,7 @@ class Alternc_Api_Auth_Sharedsecret implements Alternc_Api_Auth_Interface {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // class Alternc_Api_Auth_Sharedsecret
|
// class Alternc_Api_Auth_Sharedsecret
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ class Alternc_Api_Legacyobject {
|
||||||
$this->admin->enabled = $this->isAdmin;
|
$this->admin->enabled = $this->isAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** return a proper Alternc_Api_Response from an error class and error string
|
/** return a proper Alternc_Api_Response from an error class and error string
|
||||||
* from AlternC legacy class
|
* from AlternC legacy class
|
||||||
*/
|
*/
|
||||||
|
@ -40,5 +39,6 @@ class Alternc_Api_Legacyobject {
|
||||||
return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "[" . $err->clsid . "] " . $err->error));
|
return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "[" . $err->clsid . "] " . $err->error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} /* Aternc_Api_Legacyobject */
|
/* Aternc_Api_Legacyobject */
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
|
|
||||||
|
|
||||||
protected $dom; // m_dom instance
|
protected $dom; // m_dom instance
|
||||||
|
|
||||||
function __construct($service) {
|
function __construct($service) {
|
||||||
|
@ -14,7 +13,6 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
$this->dom = $dom;
|
$this->dom = $dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method dom->get_domain_list()
|
/** API Method from legacy class method dom->get_domain_list()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* may be "uid" to only return domains for a specific user-id
|
* may be "uid" to only return domains for a specific user-id
|
||||||
|
@ -46,18 +44,22 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
while ($me = $stmt->fetch(PDO::FETCH_OBJ)) {
|
while ($me = $stmt->fetch(PDO::FETCH_OBJ)) {
|
||||||
$result[$me->domaine] = $me;
|
$result[$me->domaine] = $me;
|
||||||
}
|
}
|
||||||
$offset=-1; $count=-1;
|
$offset = -1;
|
||||||
if (isset($options["count"])) $count=intval($options["count"]);
|
$count = -1;
|
||||||
if (isset($options["offset"])) $offset=intval($options["offset"]);
|
if (isset($options["count"]))
|
||||||
|
$count = intval($options["count"]);
|
||||||
|
if (isset($options["offset"]))
|
||||||
|
$offset = intval($options["offset"]);
|
||||||
if ($offset != -1 || $count != -1) {
|
if ($offset != -1 || $count != -1) {
|
||||||
if ($offset<0 || $offset>count($result)) $offset=0;
|
if ($offset < 0 || $offset > count($result))
|
||||||
if ($count<0 || $count>1000) $count=1000;
|
$offset = 0;
|
||||||
|
if ($count < 0 || $count > 1000)
|
||||||
|
$count = 1000;
|
||||||
$result = array_slice($result, $offset, $count);
|
$result = array_slice($result, $offset, $count);
|
||||||
}
|
}
|
||||||
return new Alternc_Api_Response(array("content" => $result));
|
return new Alternc_Api_Response(array("content" => $result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method dom->add_domain()
|
/** API Method from legacy class method dom->add_domain()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* mandatory parameters: domain(str), dns(bool)
|
* mandatory parameters: domain(str), dns(bool)
|
||||||
|
@ -85,8 +87,7 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
$options["noerase"] = false;
|
$options["noerase"] = false;
|
||||||
$options["force"] = false;
|
$options["force"] = false;
|
||||||
}
|
}
|
||||||
$did=$this->dom->add_domain($options["domain"], $options["dns"], $options["noerase"],
|
$did = $this->dom->add_domain($options["domain"], $options["dns"], $options["noerase"], $options["force"], $options["isslave"], $options["slavedom"]);
|
||||||
$options["force"], $options["isslave"], $options["slavedom"]);
|
|
||||||
if (!$did) {
|
if (!$did) {
|
||||||
return $this->alterncLegacyErrorManager();
|
return $this->alterncLegacyErrorManager();
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,8 +95,6 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method dom->edit_domain()
|
/** API Method from legacy class method dom->edit_domain()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* mandatory parameters: domain(str), dns(bool)
|
* mandatory parameters: domain(str), dns(bool)
|
||||||
|
@ -122,8 +121,7 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
if (!$this->isAdmin) { // only admin can change the options below:
|
if (!$this->isAdmin) { // only admin can change the options below:
|
||||||
$options["force"] = false;
|
$options["force"] = false;
|
||||||
}
|
}
|
||||||
$did=$this->dom->edit_domain($options["domain"], $options["dns"], $options["gesmx"],
|
$did = $this->dom->edit_domain($options["domain"], $options["dns"], $options["gesmx"], $options["force"], $options["ttl"]);
|
||||||
$options["force"], $options["ttl"]);
|
|
||||||
if (!$did) {
|
if (!$did) {
|
||||||
return $this->alterncLegacyErrorManager();
|
return $this->alterncLegacyErrorManager();
|
||||||
} else {
|
} else {
|
||||||
|
@ -131,8 +129,6 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method dom->del_domain()
|
/** API Method from legacy class method dom->del_domain()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* mandatory parameters: domain
|
* mandatory parameters: domain
|
||||||
|
@ -150,5 +146,6 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // class Alternc_Api_Object_Domain
|
// class Alternc_Api_Object_Domain
|
||||||
|
|
|
@ -13,7 +13,6 @@ class Alternc_Api_Object_Ftp extends Alternc_Api_Legacyobject {
|
||||||
$this->ftp = $ftp;
|
$this->ftp = $ftp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method ftp->add_ftp()
|
/** API Method from legacy class method ftp->add_ftp()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* mandatory parameters: prefix, login, pass, dir
|
* mandatory parameters: prefix, login, pass, dir
|
||||||
|
@ -38,7 +37,6 @@ class Alternc_Api_Object_Ftp extends Alternc_Api_Legacyobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method ftp->put_ftp_details()
|
/** API Method from legacy class method ftp->put_ftp_details()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* mandatory parameters: id
|
* mandatory parameters: id
|
||||||
|
@ -60,7 +58,8 @@ class Alternc_Api_Object_Ftp extends Alternc_Api_Legacyobject {
|
||||||
$options[$key] = $old[$key];
|
$options[$key] = $old[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isset($options["pass"])) $options["pass"]="";
|
if (!isset($options["pass"]))
|
||||||
|
$options["pass"] = "";
|
||||||
$result = $this->ftp->put_ftp_details($id, $options["prefix"], $options["login"], $options["pass"], $options["dir"]);
|
$result = $this->ftp->put_ftp_details($id, $options["prefix"], $options["login"], $options["pass"], $options["dir"]);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return $this->alterncLegacyErrorManager();
|
return $this->alterncLegacyErrorManager();
|
||||||
|
@ -69,7 +68,6 @@ class Alternc_Api_Object_Ftp extends Alternc_Api_Legacyobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method ftp->del_ftp()
|
/** API Method from legacy class method ftp->del_ftp()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* mandatory parameters: id
|
* mandatory parameters: id
|
||||||
|
@ -87,7 +85,6 @@ class Alternc_Api_Object_Ftp extends Alternc_Api_Legacyobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** API Method from legacy class method ftp->get_list()
|
/** API Method from legacy class method ftp->get_list()
|
||||||
* @param $options a hash with parameters transmitted to legacy call
|
* @param $options a hash with parameters transmitted to legacy call
|
||||||
* non-mandatory parameters:
|
* non-mandatory parameters:
|
||||||
|
@ -99,17 +96,23 @@ class Alternc_Api_Object_Ftp extends Alternc_Api_Legacyobject {
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return $this->alterncLegacyErrorManager();
|
return $this->alterncLegacyErrorManager();
|
||||||
} else {
|
} else {
|
||||||
$offset=-1; $count=-1;
|
$offset = -1;
|
||||||
if (isset($options["count"])) $count=intval($options["count"]);
|
$count = -1;
|
||||||
if (isset($options["offset"])) $offset=intval($options["offset"]);
|
if (isset($options["count"]))
|
||||||
|
$count = intval($options["count"]);
|
||||||
|
if (isset($options["offset"]))
|
||||||
|
$offset = intval($options["offset"]);
|
||||||
if ($offset != -1 || $count != -1) {
|
if ($offset != -1 || $count != -1) {
|
||||||
if ($offset<0 || $offset>count($result)) $offset=0;
|
if ($offset < 0 || $offset > count($result))
|
||||||
if ($count<0 || $count>1000) $count=1000;
|
$offset = 0;
|
||||||
|
if ($count < 0 || $count > 1000)
|
||||||
|
$count = 1000;
|
||||||
$result = array_slice($result, $offset, $count);
|
$result = array_slice($result, $offset, $count);
|
||||||
}
|
}
|
||||||
return new Alternc_Api_Response(array("content" => $result));
|
return new Alternc_Api_Response(array("content" => $result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // class Alternc_Api_Object_Ftp
|
// class Alternc_Api_Object_Ftp
|
|
@ -25,18 +25,21 @@ class Alternc_Api_Request {
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $object;
|
public $object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* must link to a Alternc_Api_Object_Interface method
|
* must link to a Alternc_Api_Object_Interface method
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $action;
|
public $action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bag of data
|
* bag of data
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $options;
|
public $options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Bag of data
|
* Bag of data
|
||||||
|
@ -45,7 +48,6 @@ class Alternc_Api_Request {
|
||||||
*/
|
*/
|
||||||
public $metadata;
|
public $metadata;
|
||||||
|
|
||||||
|
|
||||||
const ERR_MISSING_PARAMETER = 111801;
|
const ERR_MISSING_PARAMETER = 111801;
|
||||||
|
|
||||||
function __construct($options) {
|
function __construct($options) {
|
||||||
|
@ -96,8 +98,6 @@ class Alternc_Api_Request {
|
||||||
if (isset($options["metadata"])) {
|
if (isset($options["metadata"])) {
|
||||||
$this->metadata = $options["metadata"];
|
$this->metadata = $options["metadata"];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -12,7 +12,6 @@ class Alternc_Api_Response {
|
||||||
const ERR_DISABLED_ACCOUNT = 221801;
|
const ERR_DISABLED_ACCOUNT = 221801;
|
||||||
const ERR_INVALID_AUTH = 221802;
|
const ERR_INVALID_AUTH = 221802;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Result code. 0 means success
|
* Result code. 0 means success
|
||||||
*
|
*
|
||||||
|
@ -41,7 +40,6 @@ class Alternc_Api_Response {
|
||||||
*/
|
*/
|
||||||
public $metadata;
|
public $metadata;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize a response object
|
* initialize a response object
|
||||||
* @param options any of the public above
|
* @param options any of the public above
|
||||||
|
@ -49,11 +47,11 @@ class Alternc_Api_Response {
|
||||||
public function __construct($options = array()) {
|
public function __construct($options = array()) {
|
||||||
$os = array("code", "message", "content", "metadata");
|
$os = array("code", "message", "content", "metadata");
|
||||||
foreach ($os as $o) {
|
foreach ($os as $o) {
|
||||||
if (isset($options[$o])) $this->$o=$options[$o];
|
if (isset($options[$o]))
|
||||||
|
$this->$o = $options[$o];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats response to json
|
* Formats response to json
|
||||||
*
|
*
|
||||||
|
@ -63,8 +61,7 @@ class Alternc_Api_Response {
|
||||||
return json_encode(get_object_vars($this));
|
return json_encode(get_object_vars($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// class Alternc_Api_Response
|
||||||
|
|
||||||
} // class Alternc_Api_Response
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
*/
|
*/
|
||||||
class Alternc_Api_Service {
|
class Alternc_Api_Service {
|
||||||
|
|
||||||
|
|
||||||
public $db; // PDO object
|
public $db; // PDO object
|
||||||
private $loggerList; // List of loggers
|
private $loggerList; // List of loggers
|
||||||
private $allowedAuth; // list of allowed authenticators
|
private $allowedAuth; // list of allowed authenticators
|
||||||
|
@ -36,7 +35,6 @@ class Alternc_Api_Service {
|
||||||
*
|
*
|
||||||
* @return create the object
|
* @return create the object
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function __construct($options) {
|
function __construct($options) {
|
||||||
|
|
||||||
// What DB shall we connect to?
|
// What DB shall we connect to?
|
||||||
|
@ -57,15 +55,16 @@ class Alternc_Api_Service {
|
||||||
|
|
||||||
// To which logger(s) shall we log to?
|
// To which logger(s) shall we log to?
|
||||||
if (isset($options["loggerAdapter"])) {
|
if (isset($options["loggerAdapter"])) {
|
||||||
if (!is_array($options["loggerAdapter"])) $options["loggerAdapter"]=array($options["loggerAdapter"]);
|
if (!is_array($options["loggerAdapter"]))
|
||||||
|
$options["loggerAdapter"] = array($options["loggerAdapter"]);
|
||||||
foreach ($options["loggerAdapter"] as $la) {
|
foreach ($options["loggerAdapter"] as $la) {
|
||||||
if ($la instanceof Psr\Log\LoggerInterface)
|
if ($la instanceof Psr\Log\LoggerInterface)
|
||||||
$this->loggerList[] = $la;
|
$this->loggerList[] = $la;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // __construct
|
// __construct
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticate into an AlternC server
|
* Authenticate into an AlternC server
|
||||||
|
@ -121,7 +120,6 @@ class Alternc_Api_Service {
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage an API Call
|
* Manage an API Call
|
||||||
* @param Alternc_Api_Request $request The API call
|
* @param Alternc_Api_Request $request The API call
|
||||||
|
@ -149,12 +147,10 @@ class Alternc_Api_Service {
|
||||||
return new Alternc_Api_Response(array("code" => self::ERR_ACTION_NOT_FOUND, "message" => "Action not found for this object in this AlternC's instance"));
|
return new Alternc_Api_Response(array("code" => self::ERR_ACTION_NOT_FOUND, "message" => "Action not found for this object in this AlternC's instance"));
|
||||||
|
|
||||||
$request->token = $this->token; // we receive $request->token_hash as a STRING, but we transmit its object as an Alternc_Api_Token.
|
$request->token = $this->token; // we receive $request->token_hash as a STRING, but we transmit its object as an Alternc_Api_Token.
|
||||||
|
|
||||||
// TODO: log this Api Call
|
// TODO: log this Api Call
|
||||||
return $object->$action($request->options);
|
return $object->$action($request->options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for the databaseAdapter
|
* Getter for the databaseAdapter
|
||||||
* (used by authAdapter)
|
* (used by authAdapter)
|
||||||
|
@ -163,8 +159,7 @@ class Alternc_Api_Service {
|
||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// class Alternc_Api_Service
|
||||||
|
|
||||||
} // class Alternc_Api_Service
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
class Alternc_Api_Token {
|
class Alternc_Api_Token {
|
||||||
|
|
||||||
|
|
||||||
const ERR_DATABASE_ERROR = 112001;
|
const ERR_DATABASE_ERROR = 112001;
|
||||||
const ERR_INVALID_ARGUMENT = 112002;
|
const ERR_INVALID_ARGUMENT = 112002;
|
||||||
const ERR_MISSING_ARGUMENT = 112003;
|
const ERR_MISSING_ARGUMENT = 112003;
|
||||||
|
@ -33,7 +32,6 @@ class Alternc_Api_Token {
|
||||||
*/
|
*/
|
||||||
public $token;
|
public $token;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* how long (seconds) is a token valid
|
* how long (seconds) is a token valid
|
||||||
*
|
*
|
||||||
|
@ -41,12 +39,12 @@ class Alternc_Api_Token {
|
||||||
*/
|
*/
|
||||||
public $tokenDuration = 2678400; // default is a month
|
public $tokenDuration = 2678400; // default is a month
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize a token object
|
* initialize a token object
|
||||||
* @param options any of the public above
|
* @param options any of the public above
|
||||||
* may contain a dbAdapter, in that case create() will be available
|
* may contain a dbAdapter, in that case create() will be available
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function __construct($options = array()) {
|
public function __construct($options = array()) {
|
||||||
|
|
||||||
if (isset($options["uid"]) && is_int($options["uid"]))
|
if (isset($options["uid"]) && is_int($options["uid"]))
|
||||||
|
@ -54,10 +52,8 @@ class Alternc_Api_Token {
|
||||||
|
|
||||||
if (isset($options["isAdmin"]) && is_bool($options["isAdmin"]))
|
if (isset($options["isAdmin"]) && is_bool($options["isAdmin"]))
|
||||||
$this->isAdmin = $options["isAdmin"];
|
$this->isAdmin = $options["isAdmin"];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats response to json
|
* Formats response to json
|
||||||
*
|
*
|
||||||
|
@ -71,7 +67,6 @@ class Alternc_Api_Token {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new token in the DB for the associated user/admin
|
* Create a new token in the DB for the associated user/admin
|
||||||
*
|
*
|
||||||
|
@ -92,14 +87,11 @@ class Alternc_Api_Token {
|
||||||
$stmt = $db->prepare("INSERT IGNORE INTO token SET token=?, expire=DATE_ADD(NOW(), INTERVAL ? SECOND), data=?");
|
$stmt = $db->prepare("INSERT IGNORE INTO token SET token=?, expire=DATE_ADD(NOW(), INTERVAL ? SECOND), data=?");
|
||||||
$stmt->execute(array($token->token, $token->tokenDuration, $token->toJson()));
|
$stmt->execute(array($token->token, $token->tokenDuration, $token->toJson()));
|
||||||
$rows = $stmt->rowCount();
|
$rows = $stmt->rowCount();
|
||||||
|
|
||||||
} while ($rows == 0); // prevent collisions
|
} while ($rows == 0); // prevent collisions
|
||||||
|
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check and return a token
|
* Check and return a token
|
||||||
* @param $token string a 32-chars token
|
* @param $token string a 32-chars token
|
||||||
|
@ -122,7 +114,6 @@ class Alternc_Api_Token {
|
||||||
return new Alternc_Api_Response(array("code" => self::ERR_INVALID_TOKEN, "message" => "Invalid token"));
|
return new Alternc_Api_Response(array("code" => self::ERR_INVALID_TOKEN, "message" => "Invalid token"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a new random token
|
* Generate a new random token
|
||||||
* @return string
|
* @return string
|
||||||
|
@ -135,6 +126,7 @@ class Alternc_Api_Token {
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // class Alternc_Api_Response
|
// class Alternc_Api_Response
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue