Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
xdrm-brackets | a4ba4fdc9a | |
xdrm-brackets | 5cdc2f9945 |
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/* [0] On definit la racine __BUILD__ si c'est pas deja fait
|
/* [1] On definit les chemins absolus si c'est pas deja fait
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
if( !defined('__ROOT__') ) define('__ROOT__', dirname(__FILE__) );
|
if( !defined('__ROOT__') ) define('__ROOT__', dirname(__FILE__) );
|
||||||
if( !defined('__CONFIG__') ) define('__CONFIG__', __ROOT__.'/config' );
|
if( !defined('__CONFIG__') ) define('__CONFIG__', __ROOT__.'/config' );
|
||||||
|
@ -8,8 +8,6 @@
|
||||||
if( !defined('__PUBLIC__') ) define('__PUBLIC__', __ROOT__.'/public_html' );
|
if( !defined('__PUBLIC__') ) define('__PUBLIC__', __ROOT__.'/public_html' );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ACTIVE LE DEBUGGAGE (WARNING + EXCEPTION)
|
/* ACTIVE LE DEBUGGAGE (WARNING + EXCEPTION)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +19,18 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Secure Hash Function
|
||||||
|
*
|
||||||
|
* @raw<String> Data to hash
|
||||||
|
* @salt<String> Salt to use for hashing
|
||||||
|
* @pepper<String> Pepper to use for hashing
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function secure_hash(String $raw, String $salt='2104\'dsa:">AS"D:', String $pepper='3894.234123;\'21'){
|
||||||
|
return hash('sha512', $pepper.hash('sha512', $raw.$salt));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* AUTOLOADER
|
/* AUTOLOADER
|
||||||
*
|
*
|
||||||
|
@ -46,6 +56,4 @@
|
||||||
spl_autoload_register('autoloader', false, true);
|
spl_autoload_register('autoloader', false, true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -3,15 +3,69 @@
|
||||||
namespace api\module;
|
namespace api\module;
|
||||||
|
|
||||||
use \error\core\Error;
|
use \error\core\Error;
|
||||||
|
use \error\core\Err;
|
||||||
|
use \database\core\Repo;
|
||||||
|
|
||||||
|
|
||||||
class admin{
|
class admin{
|
||||||
|
|
||||||
|
|
||||||
|
/* (1) Return an admin data
|
||||||
|
*
|
||||||
|
* @id_admin<id> [OPT] UID de l'administrateur
|
||||||
|
*
|
||||||
|
* @return data<Array> Administrateurs correspondants
|
||||||
|
*
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
public static function get($args){
|
||||||
|
extract($args);
|
||||||
|
|
||||||
|
/* (1) If @id_admin is set -> get by id
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
if( is_numeric($id_admin) ){
|
||||||
|
|
||||||
|
/* (1) Search admin by id */
|
||||||
|
$fetch_admin = Repo::request('admin', 'getById', $id_admin);
|
||||||
|
|
||||||
|
/* (2) If not found -> return empty data */
|
||||||
|
if( !$fetch_admin )
|
||||||
|
return [ 'data' => [] ];
|
||||||
|
|
||||||
|
/* (3) Return fetched admin */
|
||||||
|
return [ 'data' => [$fetch_admin] ];
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Else -> get all
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
}else
|
||||||
|
return [ 'data' => Repo::request('admin', 'getAll') ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Creates a new administrator
|
||||||
|
*
|
||||||
|
* @username<string> Identifiant de l'administrateur
|
||||||
|
* @mail<string> Adresse mail de l'administrateur
|
||||||
|
* @password<string> Mot de passe de l'administrateur
|
||||||
|
*
|
||||||
|
* @return id_admin<id> UID de l'administrateur crée
|
||||||
|
*
|
||||||
|
---------------------------------------------------------*/
|
||||||
public static function post($args){
|
public static function post($args){
|
||||||
extract($args);
|
extract($args);
|
||||||
|
|
||||||
return [ 'admin' => 'post' ];
|
/* (1) Création admin */
|
||||||
|
$id_created = Repo::request('admin', 'create', $username, $mail, $password);
|
||||||
|
|
||||||
|
/* (2) Gestion erreur */
|
||||||
|
if( $id_created === false )
|
||||||
|
return [ 'error' => new Error(Err::RepoError) ];
|
||||||
|
|
||||||
|
/* (3) Renvoi @id_admin */
|
||||||
|
return [ 'id_admin' => $id_created ];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
public function getAll(){
|
public function getAll(){
|
||||||
|
|
||||||
/* (1) Statement */
|
/* (1) Statement */
|
||||||
$st = $this->pdo->query("SELECT * FROM `admin` ORDER BY `username` ASC");
|
$st = $this->pdo->query("SELECT `id_admin`, `username`, `mail` FROM `admin` ORDER BY `username` ASC");
|
||||||
|
|
||||||
/* (2) Fetched data */
|
/* (2) Fetched data */
|
||||||
return $st->fetchAll();
|
return $st->fetchAll();
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
public function getById(int $id_admin){
|
public function getById(int $id_admin){
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("SELECT * FROM `admin` WHERE `id_admin` = :id_admin LIMIT 1");
|
$pst = $this->pdo->prepare("SELECT `id_admin`, `username`, `mail` FROM `admin` WHERE `id_admin` = :id_admin LIMIT 1");
|
||||||
|
|
||||||
/* (2) Bind variables */
|
/* (2) Bind variables */
|
||||||
$pst->bindParam(':id_admin', $id_admin, \PDO::PARAM_INT);
|
$pst->bindParam(':id_admin', $id_admin, \PDO::PARAM_INT);
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
public function getByMail(String $mail){
|
public function getByMail(String $mail){
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("SELECT * FROM `admin` WHERE `mail` = :mail LIMIT 1");
|
$pst = $this->pdo->prepare("SELECT `id_admin`, `username`, `mail` FROM `admin` WHERE `mail` = :mail LIMIT 1");
|
||||||
|
|
||||||
/* (2) Bind variables */
|
/* (2) Bind variables */
|
||||||
$pst->bindParam(':mail', $mail, \PDO::PARAM_STR, 50);
|
$pst->bindParam(':mail', $mail, \PDO::PARAM_STR, 50);
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
public function getByUsername(String $username){
|
public function getByUsername(String $username){
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("SELECT * FROM `admin` WHERE `username` = :username LIMIT 1");
|
$pst = $this->pdo->prepare("SELECT `id_admin`, `username`, `mail` FROM `admin` WHERE `username` = :username LIMIT 1");
|
||||||
|
|
||||||
/* (2) Bind variables */
|
/* (2) Bind variables */
|
||||||
$pst->bindParam(':username', $username, \PDO::PARAM_STR, 20);
|
$pst->bindParam(':username', $username, \PDO::PARAM_STR, 20);
|
||||||
|
@ -109,7 +109,7 @@
|
||||||
public function getByToken(String $token){
|
public function getByToken(String $token){
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$pst = $this->pdo->prepare("SELECT * FROM `admin` WHERE `token` is not NULL AND `token` = :token LIMIT 1");
|
$pst = $this->pdo->prepare("SELECT `id_admin`, `username`, `mail` FROM `admin` WHERE `token` is not NULL AND `token` = :token LIMIT 1");
|
||||||
|
|
||||||
/* (2) Bind variables */
|
/* (2) Bind variables */
|
||||||
$pst->bindParam(':token', $token, \PDO::PARAM_STR, 128);
|
$pst->bindParam(':token', $token, \PDO::PARAM_STR, 128);
|
||||||
|
|
|
@ -28,9 +28,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"GET": {
|
"GET": {
|
||||||
"description": "Deletes an administrator",
|
"description": "Gets an administrator | Gets all administrators if no id defined",
|
||||||
"permissions": [["admin"]],
|
"permissions": [["admin"]],
|
||||||
"parameters": {}
|
"parameters": {
|
||||||
|
"URL0": { "description": "The UID of the wanted administrator.", "type": "id", "optional": true, "rename": "id_admin" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue