From 2dcbb7bd7d630748317e2d05c8ab3615b6316227 Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Mon, 6 May 2019 17:54:54 +0200 Subject: [PATCH] user add : moins de ldap... (suite) --- src/Controller/MaterielsController.php | 6 +++--- src/Controller/UsersController.php | 6 +++--- src/Model/Table/LdapConnectionsTable.php | 9 +++++++-- src/Template/Materiels/add.ctp | 15 ++++++++------- src/Template/Materiels/edit.ctp | 15 ++++++++------- src/Template/Users/add.ctp | 24 ++++++++++-------------- 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/Controller/MaterielsController.php b/src/Controller/MaterielsController.php index a1a78ff..e8b31f3 100755 --- a/src/Controller/MaterielsController.php +++ b/src/Controller/MaterielsController.php @@ -939,8 +939,8 @@ class MaterielsController extends AppController // HOWTO: https://book.cakephp.org/3.0/en/orm.html //$users = TableRegistry::get('LdapConnections')->getListUsers(); //$users = TableRegistry::get('LdapConnections')->getUsersWithNameAndEmail(); - $users_name_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); - $users_name = array_keys($users_name_and_email); + $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); + $users_name = array_keys($users_login_and_email); $users_option_list = []; for ($i = 0; $i < sizeof($users_name); $i ++) { // $users_option_list["Etienne Pallier"] = "Etienne Pallier" @@ -1038,7 +1038,7 @@ class MaterielsController extends AppController 'lieu_detail', 'fournisseurs', //'utilisateurs', - 'users_name_and_email', 'users_option_list', + 'users_login_and_email', 'users_option_list', // Gestionnaires (id=>name): 'administrateurs' )); diff --git a/src/Controller/UsersController.php b/src/Controller/UsersController.php index 5b74212..6db3d0a 100755 --- a/src/Controller/UsersController.php +++ b/src/Controller/UsersController.php @@ -220,8 +220,8 @@ class UsersController extends AppController // On recup tous les users du LDAP (ou fakeLDAP si on n'est pas en mode LDAP) //$users = TableRegistry::get('LdapConnections')->getListUsers(); //sort($users); - $users_name_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); - $users_name = array_keys($users_name_and_email); + $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); + $users_name = array_keys($users_login_and_email); // Formatage en $users_option_list["Etienne Pallier"] = "Etienne Pallier" ... $users_option_list = []; for ($i = 0; $i < sizeof($users_name); $i ++) { @@ -237,7 +237,7 @@ class UsersController extends AppController // "user" est l'utilisateur $user créé au début, et qui est vide $this->set(compact('user', 'groupesMetiers', - 'users_option_list', 'users_name_and_email', + 'users_option_list', 'users_login_and_email', 'groupesThematiques', 'sur_categorie') ); $this->set('_serialize', [ diff --git a/src/Model/Table/LdapConnectionsTable.php b/src/Model/Table/LdapConnectionsTable.php index a2707e0..154127c 100755 --- a/src/Model/Table/LdapConnectionsTable.php +++ b/src/Model/Table/LdapConnectionsTable.php @@ -276,14 +276,19 @@ class LdapConnectionsTable extends AppTable // Sort users //sort($u); //debug($u); + //var_dump($u[0]); // (EP) Refactorisation pour éviter code redondant ci-dessous, c'était pourtant pas compliqué, poil dans la main... $nb_users = $this->LDAP_USED ? $u['count'] : sizeof($u)-1; for ($i = 0; $i < $nb_users; $i ++) // $utilisateurs["Pallier Etienne"] = ["email"] - $usersWithNameAndEmail[ $u[$i]['sn'][0].' '.$u[$i]['givenname'][0] ] = $u[$i]['mail'][0]; - //debug($usersWithNameAndEmail); + ////$usersWithNameAndEmail[ $u[$i]['sn'][0].' '.$u[$i]['givenname'][0] ] = $u[$i]['mail'][0]; + $usersWithNameAndEmail[ $u[$i]['sn'][0].' '.$u[$i]['givenname'][0] ] = array( + "login" => $u[$i]['uid'][0], + "email" => $u[$i]['mail'][0] + ); // Sort users (without modifying the keys, don't use sort() but asort() !!!!!!!!!!!!!) ksort($usersWithNameAndEmail); + //debug($usersWithNameAndEmail); return $usersWithNameAndEmail; } diff --git a/src/Template/Materiels/add.ctp b/src/Template/Materiels/add.ctp index 66d8661..d1b4b59 100755 --- a/src/Template/Materiels/add.ctp +++ b/src/Template/Materiels/add.ctp @@ -5,11 +5,11 @@ * Variables passed to this view by the Controller : */ $users_option_list = $users_option_list; -$users_name_and_email = $users_name_and_email; +$users_login_and_email = $users_login_and_email; // TODO: yena d'autres... il faut les lister toutes ici, pour plus de clarté //debug($users_option_list); -//debug($users_name_and_email); +//debug($users_login_and_email); use Cake\ORM\TableRegistry; if (isset($cpMateriel)) { @@ -360,11 +360,11 @@ echo $this->element('menu_form', [ $(document).ready(function() { - // Convert (once for all) PHP $users_name_and_email array to JAVASCRIPT array + // Convert (once for all) PHP $users_login_and_email array to JAVASCRIPT array //Implode Method //var array = [INF?php echo implode($array, ","); ?SUP]; //JSON Method - var users_name_and_email = ; + var users_login_and_email = ; /** * @@ -412,13 +412,14 @@ $(document).ready(function() { * * Event "Nom utilisateur" change => "Email" change * - * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_name_and_email ??? - * (EP) New method, quicker, get email directly from PHP $users_name_and_email array + * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_login_and_email ??? + * (EP) New method, quicker, get email directly from PHP $users_login_and_email array * (OLD code is below, "fetch email via AJAX request to UsersController.getLdapEmail") */ $("#nom-responsable").bind("change", function(event) { var nom_resp = $("#nom-responsable").val(); - var new_email = users_name_and_email[nom_resp]; + //var new_email = users_login_and_email[nom_resp]; + var new_email = users_login_and_email[nom_resp]["email"]; $("#email-responsable").val(new_email); }); diff --git a/src/Template/Materiels/edit.ctp b/src/Template/Materiels/edit.ctp index 44403da..c2e8148 100755 --- a/src/Template/Materiels/edit.ctp +++ b/src/Template/Materiels/edit.ctp @@ -6,11 +6,11 @@ * Variables passed to this view by the Controller : */ $users_option_list = $users_option_list; -$users_name_and_email = $users_name_and_email; +$users_login_and_email = $users_login_and_email; // TODO: yena d'autres... il faut les lister toutes ici, pour plus de clarté //debug($users_option_list); -//debug($users_name_and_email); +//debug($users_login_and_email); use Cake\ORM\TableRegistry; @@ -463,11 +463,11 @@ echo $this->element('menu_form', [ $(document).ready(function () { - // Convert (once for all) PHP $users_name_and_email array to JAVASCRIPT array + // Convert (once for all) PHP $users_login_and_email array to JAVASCRIPT array //Implode Method //var array = [INF?php echo implode($array, ","); ?SUP]; //JSON Method - var users_name_and_email = ; + var users_login_and_email = ; /** * Event DOMAINE change @@ -530,13 +530,14 @@ $(document).ready(function () { * * Event "Nom utilisateur" change => "Email" change * - * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_name_and_email ??? - * (EP) New method, quicker, get email directly from PHP $users_name_and_email array + * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_login_and_email ??? + * (EP) New method, quicker, get email directly from PHP $users_login_and_email array * (OLD code is below (at the end), "fetch email via AJAX request to UsersController.getLdapEmail") */ $("#nom-responsable").bind("change", function(event) { var nom_resp = $("#nom-responsable").val(); - var new_email = users_name_and_email[nom_resp]; + //var new_email = users_login_and_email[nom_resp]; + var new_email = users_login_and_email[nom_resp]["email"]; $("#email-responsable").val(new_email); }); diff --git a/src/Template/Users/add.ctp b/src/Template/Users/add.ctp index f798601..fc04d67 100755 --- a/src/Template/Users/add.ctp +++ b/src/Template/Users/add.ctp @@ -1,14 +1,14 @@ 'input required' ]); } + // fake LDAP else { echo $this->Form->control('newname', [ @@ -114,21 +115,21 @@ if ($LDAP_USED) { /** * Quand on selectionne un utilisateur dans la liste => on met à jour son login et son email (en readonly) - * (EP 6/5/19) New method, quicker, get email directly from PHP $users_name_and_email array + * (EP 6/5/19) New method, quicker, get email directly from PHP $users_login_and_email array * (OLD code is at end of file) * * Event "Nom utilisateur" change => "login" and "email" change * - * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_name_and_email ??? + * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_login_and_email ??? */ $(document).ready(function () { - // Convert (once for all) PHP $users_name_and_email array to JAVASCRIPT array + // Convert (once for all) PHP $users_login_and_email array to JAVASCRIPT array //Implode Method //var array = [INF?php echo implode($array, ","); ?SUP]; //JSON Method - var users_name_and_email = ; + var users_login_and_email = ; $("#nom").bind("change", function(event) { @@ -137,16 +138,11 @@ $(document).ready(function () { var user_name = $("#nom").val(); /* Mise a jour du login */ - var url = document.URL; - var loginUrl = url.replace("add", "getLdapLogin/"); - $.ajax({ - url: loginUrl + $("#nom").val() - }).done(function(data) { - $("#username").val(data) - }); + var new_login = users_login_and_email[user_name]["login"]; + $("#username").val(new_login); /* Mise a jour du mail */ - var new_email = users_name_and_email[user_name]; + var new_email = users_login_and_email[user_name]["email"]; $("#email").val(new_email); }); // ON "nom" field change -- libgit2 0.21.2