83 lines
1.9 KiB
PHP
83 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace manager\repo;
|
|
use \manager\Database;
|
|
|
|
class token{
|
|
|
|
/* Gestion de la table Token (pour secu) et des derivations
|
|
*
|
|
* 1. Gestion des access
|
|
* - getById(id_token)
|
|
* - getAll()
|
|
*
|
|
* 2. Gestion de la verification
|
|
* - check(token, id_personne)
|
|
*
|
|
* 3. Gestion de la
|
|
* - merge(idA, idB)
|
|
*
|
|
* 4. Gestion de creation
|
|
* - create(pseudo, nom, prenom, facebook, telephone)
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
/* RETOURNE LA LISTE DE TOUS LES TOKENS
|
|
*
|
|
* @return tokens<Array> Liste de tous les tokens
|
|
*
|
|
*/
|
|
public static function getAll(){
|
|
/* [1] On prepare et execute la requete
|
|
=========================================================*/
|
|
$request = Database::getPDO()->query("SELECT id_token as id, name, token, creation, expires
|
|
FROM api_token
|
|
WHERE CURDATE() BETWEEN creation AND expires
|
|
ORDER BY creation ASC");
|
|
|
|
/* [2] On recupere et retourne les donnees
|
|
=========================================================*/
|
|
return Database::delNumeric( $request->fetchAll() );
|
|
}
|
|
|
|
|
|
|
|
|
|
/* VERIFIE SI UN TOKEN EST VALIDE
|
|
*
|
|
* @token<String> Token en question
|
|
*
|
|
* @return valid<bool> Retourne si VRAI ou FAUX le token est valid
|
|
*
|
|
*/
|
|
public static function check($token){
|
|
/* [0] Verification des INPUT
|
|
=========================================================*/
|
|
// si le format est incorrect, on retourne FAUX
|
|
if( !Database::check('sha1', $token) ) return false;
|
|
|
|
|
|
/* [1] Verification dans la base de donnees
|
|
=========================================================*/
|
|
$check = Database::getPDO()->prepare("SELECT id_token
|
|
FROM api_token
|
|
WHERE CURDATE() BETWEEN creation AND expires
|
|
AND token = :token");
|
|
$check->execute(array( ':token' => $token ));
|
|
|
|
|
|
/* [2] On retourne le resultat
|
|
=========================================================*/
|
|
return $check->fetch() !== false;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|