From e8c8ca9452c7d8856ffab054028a2083d52ccd16 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 4 Jul 2016 14:39:27 +0200 Subject: [PATCH] =?UTF-8?q?Repo=20'warehouse'=20termin=C3=A9,=20mais=20auc?= =?UTF-8?q?un=20test=20pour=20l'instant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/repo/warehouse.php | 98 ++++++++++++++++++++++++-------------- test/automate.php | 15 +++++- 2 files changed, 77 insertions(+), 36 deletions(-) diff --git a/manager/repo/warehouse.php b/manager/repo/warehouse.php index 988c095..2edd0d7 100644 --- a/manager/repo/warehouse.php +++ b/manager/repo/warehouse.php @@ -56,6 +56,49 @@ + /* MISE A JOUR DU TOKEN D'UN ENTREPOT + * + * @id_warehouse UID de l'entrepot + * + * @return new_token Renvoie le nouveau token + * + */ + public static function updateToken($id_warehouse=null){ + + /* [1] On vérifie que l'entrepot existe + =========================================================*/ + if( self::getById($id_warehouse) === false ) + return false; + + + /* [2] On met à jour le token + =========================================================*/ + /* (1) On crée un nouveau token */ + $new_token = sessionManager::secure_sha1( uniqid() ); + + /* (2) On applique le nouveau token */ + $update_token = Database::getPDO()->prepare("UPDATE warehouse + SET token = :token + WHERE id_warehouse = :id_warehouse"); + + $update_token->execute(array( + ':token' => $new_token, + ':id_warehouse' => $id_warehouse + )); + + + /* [3] On renvoie le token + =========================================================*/ + return $new_token; + + } + + + + + + + /* MODIFICATION D'UN ENTREPOT * @@ -81,40 +124,25 @@ /* [2] Modification de l'utilisateur =========================================================*/ - $edit_user = Database::getPDO()->prepare("UPDATE user - SET code = :code, - username = :username, - firstname = :firstname, - lastname = :lastname, - mail = :mail, - password = :password, - status = :status - WHERE id_user = :id_user"); - $edit_user->execute(array( - ':code' => $code, - ':username' => $username, - ':firstname' => $firstname, - ':lastname' => $lastname, - ':mail' => $mail, - ':password' => $password, - ':status' => $status, - ':id_user' => $id_user + $edit_warehouse = Database::getPDO()->prepare("UPDATE warehouse + SET name = :name, + password = :password + WHERE id_warehouse = :id_warehouse"); + $edit_warehouse->execute(array( + ':name' => $name, + ':password' => $password, + ':id_warehouse' => $id_warehouse )); /* [3] On retourne si tout a ete modifie, si erreur =========================================================*/ - $check_user = self::getById($id_user); + $check_warehouse = self::getById($id_warehouse); - $checker = $check_user['id_user'] == $id_user; - $checker = $checker && $check_user['code'] == $code; - $checker = $checker && $check_user['username'] == $username; - $checker = $checker && $check_user['firstname'] == $firstname; - $checker = $checker && $check_user['lastname'] == $lastname; - $checker = $checker && $check_user['mail'] == $mail; - $checker = $checker && $check_user['password'] == $password; - $checker = $checker && $check_user['status'] == $status; + $checker = $check_warehouse['id_warehouse'] == $id_warehouse; + $checker = $checker && $check_warehouse['name'] == $name; + $checker = $checker && $check_warehouse['password'] == $password; // On retourne l'etat de la modification return $checker; @@ -127,25 +155,25 @@ - /* SUPPRIME UN UTILISATEUR DONNE + /* SUPPRIME UN ENTREPOT DONNE * - * @id_user UID de l'utilisateur en question + * @id_warehouse UID de l'entrepot en question * - * @return status Retourne si oui ou non l'utilisateur a bien ete supprime + * @return status Retourne si oui ou non l'entrepot a bien ete supprime * */ - public static function delete($id_user){ + public static function delete($id_warehouse){ /* [1] On redige/execute la requete =========================================================*/ - $delete_user = Database::getPDO()->prepare("DELETE FROM user WHERE id_user = :id_user"); - $delete_user->execute(array( - ':id_user' => $id_user + $delete_warehouse = Database::getPDO()->prepare("DELETE FROM warehouse WHERE id_warehouse = :id_warehouse"); + $delete_warehouse->execute(array( + ':id_warehouse' => $id_warehouse )); /* [2] On verifie que l'utilisateur n'existe plus =========================================================*/ - return ( self::getById($id_user) === false ); + return ( self::getById($id_warehouse) === false ); } diff --git a/test/automate.php b/test/automate.php index a2eccc2..9c6c0c5 100755 --- a/test/automate.php +++ b/test/automate.php @@ -309,7 +309,20 @@ - + + + function createWarehouse(){ + + $insert = new Repo('warehouse/create', array( 'FifthWarehouse', 'MyPassword' ) ); + var_dump( $insert->answer() ); + + + $getAll = new Repo('warehouse/getAll'); + }createWarehouse(); + + + + ?>