2016-04-11 08:18:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\module;
|
|
|
|
use \manager\Database;
|
|
|
|
use \manager\sessionManager;
|
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Repo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class token{
|
|
|
|
|
|
|
|
|
|
|
|
/* SUPPRIME UN TOKEN D'ID DONNE
|
|
|
|
*
|
2016-04-19 13:30:33 +00:00
|
|
|
* @token_id<int> UID du token en question
|
2016-04-11 08:18:10 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-04-18 09:30:38 +00:00
|
|
|
public static function remove($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
/* [1] Suppression du token
|
2016-04-11 08:18:10 +00:00
|
|
|
=========================================================*/
|
2016-04-19 13:30:33 +00:00
|
|
|
$remove = new Repo('token/remove', array($token_id));
|
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
// On renvoie une erreur si une erreur intervient pendant la suppression
|
2016-04-19 13:30:33 +00:00
|
|
|
if( $remove->answer() === false ) return array('ModuleError' => ManagerError::ModuleError);
|
2016-04-11 08:18:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [n] Gestion du retour quand tout est normal
|
|
|
|
=========================================================*/
|
2016-04-11 10:20:34 +00:00
|
|
|
return array( 'ModuleError' => ManagerError::Success );
|
2016-04-11 08:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GENERE UN NOUVEAU TOKEN DE NOM ET EXPIRATION SPECIFIEE
|
|
|
|
*
|
|
|
|
* @name<String> Nom attribue au token
|
|
|
|
* @duration<int> Duree du token en jours
|
|
|
|
*
|
|
|
|
* @return id_token<int> Renvoie l'id du token cree
|
|
|
|
* @return FALSE Renvoie FALSE si erreur
|
|
|
|
*
|
|
|
|
*/
|
2016-04-18 09:30:38 +00:00
|
|
|
public static function generate($params){
|
|
|
|
extract($params);
|
2016-04-19 13:30:33 +00:00
|
|
|
|
2016-04-11 08:18:10 +00:00
|
|
|
/* [0] Verification des INPUT
|
|
|
|
=========================================================*/
|
2016-04-19 13:30:33 +00:00
|
|
|
if( !Database::check('varchar(4,50)', $name) || !Database::check('id', $duration) )
|
2016-04-11 08:18:10 +00:00
|
|
|
return array('ModuleError' => ManagerError::ParamError); // erreur de parametre
|
|
|
|
|
2016-04-18 09:30:38 +00:00
|
|
|
|
2016-04-11 08:18:10 +00:00
|
|
|
/* [1] On cree le token et recupere son id ou FAUX
|
|
|
|
=========================================================*/
|
|
|
|
$create = new Repo('token/generate', array($name, $duration));
|
2016-04-11 12:07:52 +00:00
|
|
|
$created = $create->answer();
|
2016-04-11 08:18:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Si erreur de creation
|
2016-04-11 12:07:52 +00:00
|
|
|
if( $created === false ) return array('ModuleError' => ManagerError::ModuleError );
|
2016-04-11 08:18:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion du retour
|
|
|
|
=========================================================*/
|
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'id_token' => $created
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-18 09:30:38 +00:00
|
|
|
|
2016-04-11 08:18:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-18 09:30:38 +00:00
|
|
|
?>
|