2016-07-06 15:36:26 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
namespace api\module;
|
|
|
|
use \database\core\Database;
|
2016-07-06 15:36:26 +00:00
|
|
|
use \manager\sessionManager;
|
2016-10-18 14:03:03 +00:00
|
|
|
use \api\core\Authentification;
|
2016-07-06 15:36:26 +00:00
|
|
|
use \manager\ManagerError;
|
2016-10-18 14:03:03 +00:00
|
|
|
use \database\core\Repo;
|
2016-07-06 15:36:26 +00:00
|
|
|
use \manager\repo\cluster as clusterRepo;
|
|
|
|
|
|
|
|
class authentificationDefault{
|
|
|
|
|
|
|
|
/* CONNEXION A UN ENTREPOT
|
|
|
|
*
|
|
|
|
* @name<String> Nom de l'entrepot
|
|
|
|
* @password<String> Mot de passe de l'entrepot
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si les crédits sont bons, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function warehouse($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-07-08 13:18:23 +00:00
|
|
|
|
|
|
|
/* [0] Par défaut, on déconnecte
|
|
|
|
=========================================================*/
|
|
|
|
$_SESSION['AUTH'] = [];
|
|
|
|
|
|
|
|
|
2016-07-06 15:36:26 +00:00
|
|
|
/* [1] On recherche un entrepot avec ce nom
|
|
|
|
=========================================================*/
|
|
|
|
$getName = new Repo('warehouse/getByName', [$name]);
|
|
|
|
|
|
|
|
$nameFetched = $getName->answer();
|
|
|
|
|
2016-07-14 07:25:09 +00:00
|
|
|
// Si aucun résultat, on retourne le status FALSE
|
2016-07-06 15:36:26 +00:00
|
|
|
if( count($nameFetched) == 0 )
|
|
|
|
return [ 'status' => false ];
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On vérifie le mot de passe
|
|
|
|
=========================================================*/
|
2016-07-07 15:59:31 +00:00
|
|
|
$hash_password = sessionManager::secure_hash($password);
|
2016-07-06 15:36:26 +00:00
|
|
|
|
2016-07-14 07:25:09 +00:00
|
|
|
// Si mot de passe faux, on retourne le status FALSE
|
2016-07-06 15:36:26 +00:00
|
|
|
if( $nameFetched[0]['password'] != $hash_password )
|
|
|
|
return [ 'status' => false ];
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On définit le token
|
|
|
|
=========================================================*/
|
|
|
|
$_SESSION['AUTH'][0] = $nameFetched[0]['token'];
|
|
|
|
|
|
|
|
// On retourne le status
|
|
|
|
return [ 'status' => true ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* CONNEXION EN TANT QU'ADMINISTRATEUR
|
|
|
|
*
|
|
|
|
* @username<String> Nom de l'administrateur
|
|
|
|
* @password<String> Mot de passe de l'administrateur
|
|
|
|
*
|
|
|
|
* @return status<Boolean> TRUE si les crédits sont bons, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function admin($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-07-08 13:18:23 +00:00
|
|
|
/* [0] Par défaut, on déconnecte l'administrateur
|
|
|
|
=========================================================*/
|
|
|
|
$_SESSION['AUTH'][1] = '';
|
|
|
|
|
|
|
|
|
2016-07-14 07:32:58 +00:00
|
|
|
/* [1] On recherche un administrateur avec ce nom
|
2016-07-06 15:36:26 +00:00
|
|
|
=========================================================*/
|
2016-07-14 07:25:09 +00:00
|
|
|
$getUsername = new Repo('admin/getByUsername', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$username
|
|
|
|
]);
|
2016-07-06 15:36:26 +00:00
|
|
|
|
|
|
|
$usernameFetched = $getUsername->answer();
|
|
|
|
|
2016-07-14 07:25:09 +00:00
|
|
|
// Si aucun résultat, on retourne le status FALSE
|
2016-07-14 07:36:18 +00:00
|
|
|
if( $usernameFetched === false )
|
2016-07-06 15:36:26 +00:00
|
|
|
return [ 'status' => false ];
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On vérifie le mot de passe
|
|
|
|
=========================================================*/
|
2016-07-07 15:59:31 +00:00
|
|
|
$hash_password = sessionManager::secure_hash($password);
|
2016-07-06 15:36:26 +00:00
|
|
|
|
2016-07-14 07:25:09 +00:00
|
|
|
// Si mot de passe faux, on retourne le status FALSE
|
2016-07-14 07:36:18 +00:00
|
|
|
if( $usernameFetched['password'] != $hash_password )
|
2016-07-06 15:36:26 +00:00
|
|
|
return [ 'status' => false ];
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On définit le token
|
|
|
|
=========================================================*/
|
2016-07-14 07:36:18 +00:00
|
|
|
$_SESSION['AUTH'][1] = $usernameFetched['token'];
|
2016-07-06 15:36:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
// On retourne le status
|
|
|
|
return [ 'status' => true ];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|