From 26b82ecf9471e222df6962facc3e597ee9fed8e8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 21 Feb 2017 15:55:40 +0100 Subject: [PATCH] Fixed `AuthSystemDefault` through repo `machine/checkToken` to return MACHINE ID (as for WAREHOUSE/ADMIN session data) + fixed code --- build/api/core/AuthSystemDefault.php | 5 ++--- build/api/module/machineDefault.php | 28 +++++++--------------------- build/database/repo/machine.php | 7 +++++-- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/build/api/core/AuthSystemDefault.php b/build/api/core/AuthSystemDefault.php index 8ce3c6d..03c8f4c 100755 --- a/build/api/core/AuthSystemDefault.php +++ b/build/api/core/AuthSystemDefault.php @@ -142,13 +142,12 @@ $checkBranch = new Repo('machine/checkToken', [ $_SESSION['WAREHOUSE']['id'], $_SESSION['AUTH'][1], $_SESSION['AUTH'][2] ]); /* (1) Si le token n'est pas valide, on retourne une erreur */ - if( $checkBranch->answer() == false ) + if( $checkBranch->answer() === false ) return false; /* (2) On met à jour les informations de l'administrateur */ $_SESSION['SATS'] = [ - 'id' => (int) $checkBranch->answer()['id_machine'], - 'name' => $checkBranch->answer()['name'] + 'id' => (int) $checkBranch->answer() ]; diff --git a/build/api/module/machineDefault.php b/build/api/module/machineDefault.php index e47246b..594ed91 100755 --- a/build/api/module/machineDefault.php +++ b/build/api/module/machineDefault.php @@ -614,17 +614,6 @@ - - - - - - - - - - - @@ -672,18 +661,15 @@ 'id_machine' => $_SESSION['SATS']['id'] ]); - var_dump('req', $log_req->error->get()); - // {2} Manage error // - if( $log_req->error->get() != Err::Success ) - continue; - - // {3} Process + get response // + // {2} Process + get response // $log_res = $log_req->dispatch(); - var_dump('res', $log_res->error->get()); - // {4} Register if success // - if( $log_res->error->get() == Err::Success ) - $fetched['history']++; + // {3} Exit on failure // + if( $log_res->error->get() != Err::Success ) + break; + + // {4} Register count if success // + $fetched['history']++; } } diff --git a/build/database/repo/machine.php b/build/database/repo/machine.php index 4f1ad85..1050b2b 100755 --- a/build/database/repo/machine.php +++ b/build/database/repo/machine.php @@ -373,7 +373,7 @@ * @token Token de synchronisation * @newToken Nouveau token de synchronisation (optionnel, uniquement quand on arrive à la fin du cycle de la hashChain) * - * @return status VRAI si le token est correct, sinon FALSE + * @return machine_id ID de la machine si correct, sinon FALSE * */ public static function checkToken($id_warehouse, $token, $newToken=null){ @@ -400,7 +400,10 @@ /* [3] On retourne que tout s'est bien déroulé =========================================================*/ - return $updated; + if( !$updated ) + return false; + + return $byToken['id_machine']; }