From b6dfc2497323c46760486f5496903bb9644d34ca Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 16 Feb 2016 09:03:12 +0100 Subject: [PATCH] - [x] [userDefault] Implementer la modification - [x] [view/js/users+machines] Modification @value plutot que @placeholder --- automate.php | 34 ++++++++++++++ config/modules.json | 4 ++ config/repositories.json | 2 + manager/module/userDefault.php | 63 ++++++++++++++++++++++++++ manager/repo/user.php | 82 +++++++++++++++++++++++++++++++++- todo.md | 6 +++ view/js/machines.js | 4 +- view/js/users.js | 16 +++---- 8 files changed, 199 insertions(+), 12 deletions(-) diff --git a/automate.php b/automate.php index 9d9ee13..e9f491b 100755 --- a/automate.php +++ b/automate.php @@ -270,4 +270,38 @@ }//getUserClusters(); + + + + + /* MODIFICATION D'UN UTILISATEUR + * + * + * @return status TRUE si aucune erreur, sinon FALSE + * + */ + function editUser(){ + $id_user = 48; + + $request = new ModuleRequest('userDefault/edit', array( + 'B1-87-EA-BF', + 'Abigail', + 'Mcmillan', + 'Savage', + 'mcmillansavage@corecom.com', + 'password', + 0 + )); + + + // ["B1-87-EA-BF","Abigail01","Mcmillan","Savage","mcmillansavage@corecom.com","password",0] + + var_dump( $request->dispatch() ); + + + return true; + + }editUser(); + + ?> \ No newline at end of file diff --git a/config/modules.json b/config/modules.json index 5cfba9c..e61ce52 100755 --- a/config/modules.json +++ b/config/modules.json @@ -12,6 +12,8 @@ "getClusters", + "edit", + "delete" ], @@ -28,6 +30,8 @@ "getClusters", + "edit", + "delete" ] diff --git a/config/repositories.json b/config/repositories.json index c421c38..0ec1141 100755 --- a/config/repositories.json +++ b/config/repositories.json @@ -9,6 +9,8 @@ "getClusters", + "edit", + "delete" ], diff --git a/manager/module/userDefault.php b/manager/module/userDefault.php index 51a0da8..d88355f 100755 --- a/manager/module/userDefault.php +++ b/manager/module/userDefault.php @@ -275,6 +275,69 @@ + /* MODIFIE UN UTILISATEUR DONNEE + * + * @code Code RFID de l'utilisateur + * @username Identifiant l'utilisateur + * @firstname Prenom de l'utilisateur + * @lastcode Nom de l'utilisateur + * @mail Adresse email de l'utilisateur + * @password Mot de passe de l'utilisateur + * @status Status de l'utilisateur + * + * @return status Retourne si oui ou non tout s'est bien deroule + * + */ + public static function edit($code=null, $username=null, $firstname=null, $lastname=null, $mail=null, $password=null, $status=null){ + /* [1] Normalisation + verification des donnees + =========================================================*/ + $password_hash = sessionManager::secure_sha1($password); + + $correct_param = Database::check('user.code', $code); + $correct_param = $correct_param && Database::check('user.username', $username); + $correct_param = $correct_param && Database::check('user.firstname', $firstname); + $correct_param = $correct_param && Database::check('user.lastname', $lastname); + $correct_param = $correct_param && Database::check('user.mail', $mail); + $correct_param = $correct_param && Database::check('user.password', $password_hash); + $correct_param = $correct_param && Database::check('user.status', $status); + + // Si les parametres ne sont pas corrects, on retourne une erreur + if( !$correct_param ) + return array('ModuleError' => ManagerError::ParamError); + + + /* [2] Recuperation de l'UID de l'utilisateur + =========================================================*/ + $getByCode = new Repo('user/getByCode', array($code)); + $getByUsername = new Repo('user/getByUsername', array($username)); + + // On recupere les resultats + $uidbycode = $getByCode->answer(); + $uidbyusername = $getByUsername->answer(); + + // On recupere l'utilisateur (si recupere avec code OU username) + $user = (is_array($uidbyusername)) ? $uidbyusername : null; + $user = (is_array($uidbycode)) ? $uidbycode : $user; + + // Si on a recupere aucun utilisateur, on retourne une erreur + if( !is_array($user) ) + return array('ModuleError' => ManagerError::ModuleError); + + + /* [3] Modification de l'utilisateur + =========================================================*/ + $request = new Repo('user/edit', array($user['id_user'], $code, $username, $firstname, $lastname, $mail, $password_hash, $status)); + $answer = $request->answer(); + + return array( + 'status' => $answer + ); + } + + + + + /* SUPPRIME UN UTILISATEUR DONNEE * * @id_user UID de l'utilisateur en question diff --git a/manager/repo/user.php b/manager/repo/user.php index d1c515c..37e3614 100755 --- a/manager/repo/user.php +++ b/manager/repo/user.php @@ -23,8 +23,8 @@ public static function create($code, $username, $firstname, $lastname, $mail, $password, $status){ /* [1] Verification de l'unicite de code+username =========================================================*/ - $check_unique = ( self::getByCode($code) == false ); - $check_unique = $check_unique && ( self::getByUsername($username) == false ); + $check_unique = !is_array(self::getByCode($code)); + $check_unique = $check_unique && !is_array(self::getByUsername($username)); // Si un utilisateur a deja ce code ou cet username, on renvoie une erreur if( !$check_unique ) @@ -257,6 +257,84 @@ + /* MODIFICATION D'UN UTILISATEUR + * + * @id_user UID de l'utilisateur + * @code Code RFID de l'utilisateur + * @username Identifiant l'utilisateur + * @firstname Prenom de l'utilisateur + * @lastcode Nom de l'utilisateur + * @mail Adresse email de l'utilisateur + * @password Mot de passe de l'utilisateur + * @status Status de l'utilisateur + * + * @return status Renvoie si oui ou non tout s'est bien passe + * + */ + public static function edit($id_user, $code, $username, $firstname, $lastname, $mail, $password, $status){ + /* [1] Verification de l'unicite de code+username (si differents) + =========================================================*/ + // On recupere les utilisateurs ayant le meme code ou username (si existent) + $getbycode = self::getByCode($code); + $getbyusername = self::getByCode($username); + + $check_unique = is_array($getbycode) && $getbycode['id_user'] == $id_user || !is_array($getbycode); + $check_unique = $check_unique && is_array($getbyusername) && $getbyusername['id_user'] == $id_user || !is_array($getbyusername); + + // Si un utilisateur a deja ce code ou cet username (sauf lui), on renvoie une erreur + if( !$check_unique ) + return false; + + /* [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 + )); + + + + /* [3] On retourne si tout a ete modifie, si erreur + =========================================================*/ + $check_user = self::getById($id_user); + + $checker = $check_user['id_user'] == $id_user; + $checker = $checker && $check_user['code'] == $code; + $checker = $checker && $check_user['username'] == $username; + var_dump($check_user['username']); + var_dump($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; + + // On retourne l'etat de la modification + return $checker; + } + + + + + + + + /* SUPPRIME UN UTILISATEUR DONNE * * @id_user UID de l'utilisateur en question diff --git a/todo.md b/todo.md index 8c87e7b..53d4240 100755 --- a/todo.md +++ b/todo.md @@ -10,14 +10,20 @@ - [ ] [view/js/users] Recherche instantanee - [ ] [view/js/machines] Recherche instantanee +- [x] [userDefault] Implementer la modification + - [ ] [userRepo] Gestion des parametres optionnels + - [ ] [view/js/users] Modification d'utilisateur +- [ ] [machineDefault] Implementer la modification - [ ] [view/js/machines] Modification de machine ######## # FAIT # ######## +- [x] [userDefault] Implementer la modification +- [x] [view/js/users+machines] Modification @value plutot que @placeholder - [x] [view/js/users] Suppression d'utilisateur - [x] [view/js/machines] Suppression de machine - [x] Correction erreur diff --git a/view/js/machines.js b/view/js/machines.js index 6f066af..b4c8df7 100644 --- a/view/js/machines.js +++ b/view/js/machines.js @@ -244,8 +244,8 @@ if( section.edit.element != null ){ machine_data = answer.machine; // Auto-remplissage du formulaire - section.edit.input.code.placeholder = machine_data.code; - section.edit.input.name.placeholder = machine_data.name; + section.edit.input.code.value = machine_data.code; + section.edit.input.name.value = machine_data.name; } }); }}autofill_edit(); diff --git a/view/js/users.js b/view/js/users.js index 08b6dc0..d55c544 100644 --- a/view/js/users.js +++ b/view/js/users.js @@ -259,14 +259,14 @@ if( section.edit.element != null ){ user_data = answer.user; // Auto-remplissage du formulaire - section.edit.input.code.placeholder = user_data.code; - section.edit.input.username.placeholder = user_data.username; - section.edit.input.firstname.placeholder = user_data.firstname; - section.edit.input.lastname.placeholder = user_data.lastname; - section.edit.input.mail.placeholder = user_data.mail; - section.edit.input.password.value = ''; - section.edit.input.status.placeholder = user_data.status; - } + section.edit.input.code.value = user_data.code; + section.edit.input.username.value = user_data.username; + section.edit.input.firstname.value = user_data.firstname; + section.edit.input.lastname.value = user_data.lastname; + section.edit.input.mail.value = user_data.mail; + section.edit.input.password.value = ''; + section.edit.input.status.value = user_data.status; + } }); }}autofill_edit();