- [x] [userDefault] Implementer la modification
- [x] [view/js/users+machines] Modification @value plutot que @placeholder
This commit is contained in:
parent
61b3fea73f
commit
b6dfc24973
34
automate.php
34
automate.php
|
@ -270,4 +270,38 @@
|
|||
}//getUserClusters();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* MODIFICATION D'UN UTILISATEUR
|
||||
*
|
||||
*
|
||||
* @return status<Boolean> 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();
|
||||
|
||||
|
||||
?>
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
"getClusters",
|
||||
|
||||
"edit",
|
||||
|
||||
"delete"
|
||||
],
|
||||
|
||||
|
@ -28,6 +30,8 @@
|
|||
|
||||
"getClusters",
|
||||
|
||||
"edit",
|
||||
|
||||
"delete"
|
||||
]
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
"getClusters",
|
||||
|
||||
"edit",
|
||||
|
||||
"delete"
|
||||
],
|
||||
|
||||
|
|
|
@ -275,6 +275,69 @@
|
|||
|
||||
|
||||
|
||||
/* MODIFIE UN UTILISATEUR DONNEE
|
||||
*
|
||||
* @code<String> Code RFID de l'utilisateur
|
||||
* @username<String> Identifiant l'utilisateur
|
||||
* @firstname<String> Prenom de l'utilisateur
|
||||
* @lastcode<String> Nom de l'utilisateur
|
||||
* @mail<String> Adresse email de l'utilisateur
|
||||
* @password<String> Mot de passe de l'utilisateur
|
||||
* @status<String> Status de l'utilisateur
|
||||
*
|
||||
* @return status<Boolean> 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<int> UID de l'utilisateur en question
|
||||
|
|
|
@ -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<int> UID de l'utilisateur
|
||||
* @code<String> Code RFID de l'utilisateur
|
||||
* @username<String> Identifiant l'utilisateur
|
||||
* @firstname<String> Prenom de l'utilisateur
|
||||
* @lastcode<String> Nom de l'utilisateur
|
||||
* @mail<String> Adresse email de l'utilisateur
|
||||
* @password<String> Mot de passe de l'utilisateur
|
||||
* @status<String> Status de l'utilisateur
|
||||
*
|
||||
* @return status<Boolean> 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<int> UID de l'utilisateur en question
|
||||
|
|
6
todo.md
6
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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -259,13 +259,13 @@ 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();
|
||||
|
|
Loading…
Reference in New Issue