From 97b75152649f6e55edbb7ad260e8f580d7747d45 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 10 Dec 2017 22:42:09 +0100 Subject: [PATCH] POST api.module.admin (added create) | upgraded autoloader.php --- autoloader.php | 18 +++++++++++++----- build/api/module/admin.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/autoloader.php b/autoloader.php index 95c4156..ca24bd1 100755 --- a/autoloader.php +++ b/autoloader.php @@ -1,6 +1,6 @@ Data to hash + * @salt Salt to use for hashing + * @pepper 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 * @@ -46,6 +56,4 @@ spl_autoload_register('autoloader', false, true); - - ?> diff --git a/build/api/module/admin.php b/build/api/module/admin.php index 97d3168..da950d1 100644 --- a/build/api/module/admin.php +++ b/build/api/module/admin.php @@ -3,6 +3,7 @@ namespace api\module; use \error\core\Error; + use \error\core\Err; use \database\core\Repo; @@ -38,6 +39,33 @@ ---------------------------------------------------------*/ }else return [ 'data' => Repo::request('admin', 'getAll') ]; + + } + + + + /* (2) Creates a new administrator + * + * @username Identifiant de l'administrateur + * @mail Adresse mail de l'administrateur + * @password Mot de passe de l'administrateur + * + * @return id_admin UID de l'administrateur crée + * + ---------------------------------------------------------*/ + public static function post($args){ + extract($args); + + /* (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 ]; + } }