NxTIC/manager/module/token.php

90 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace manager\module;
use \manager\Database;
use \manager\sessionManager;
use \manager\ManagerError;
use \manager\Repo;
class token{
/* SUPPRIME UN TOKEN D'ID DONNE
*
* @id_token<int> UID du token en question
*
*/
public static function remove($params){
extract($params);
/* [1] Suppression du token
=========================================================*/
$remove = new Repo('token/remove', array($id_token));
// On renvoie une erreur si une erreur intervient pendant la suppression
if( !$remove->answer() ) return array('ModuleError' => ManagerError::ModuleError);
/* [n] Gestion du retour quand tout est normal
=========================================================*/
return array( 'ModuleError' => ManagerError::Success );
}
/* 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
*
*/
public static function generate($params){
extract($params);
/* [0] Verification des INPUT
=========================================================*/
if( !Database::check('varchar(50)', $name) || !Database::check('numeric', $duration) )
return array('ModuleError' => ManagerError::ParamError); // erreur de parametre
/* [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();
// Si erreur de creation
2016-04-11 12:07:52 +00:00
if( $created === false ) return array('ModuleError' => ManagerError::ModuleError );
/* [2] Gestion du retour
=========================================================*/
return array(
'ModuleError' => ManagerError::Success,
'id_token' => $created
);
}
}
?>