Commit 2dcbb7bd7d630748317e2d05c8ab3615b6316227
1 parent
d29ffebd
Exists in
master
and in
2 other branches
user add : moins de ldap... (suite)
Showing
6 changed files
with
39 additions
and
36 deletions
Show diff stats
src/Controller/MaterielsController.php
... | ... | @@ -939,8 +939,8 @@ class MaterielsController extends AppController |
939 | 939 | // HOWTO: https://book.cakephp.org/3.0/en/orm.html |
940 | 940 | //$users = TableRegistry::get('LdapConnections')->getListUsers(); |
941 | 941 | //$users = TableRegistry::get('LdapConnections')->getUsersWithNameAndEmail(); |
942 | - $users_name_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
943 | - $users_name = array_keys($users_name_and_email); | |
942 | + $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
943 | + $users_name = array_keys($users_login_and_email); | |
944 | 944 | $users_option_list = []; |
945 | 945 | for ($i = 0; $i < sizeof($users_name); $i ++) { |
946 | 946 | // $users_option_list["Etienne Pallier"] = "Etienne Pallier" |
... | ... | @@ -1038,7 +1038,7 @@ class MaterielsController extends AppController |
1038 | 1038 | 'lieu_detail', |
1039 | 1039 | 'fournisseurs', |
1040 | 1040 | //'utilisateurs', |
1041 | - 'users_name_and_email', 'users_option_list', | |
1041 | + 'users_login_and_email', 'users_option_list', | |
1042 | 1042 | // Gestionnaires (id=>name): |
1043 | 1043 | 'administrateurs' |
1044 | 1044 | )); | ... | ... |
src/Controller/UsersController.php
... | ... | @@ -220,8 +220,8 @@ class UsersController extends AppController |
220 | 220 | // On recup tous les users du LDAP (ou fakeLDAP si on n'est pas en mode LDAP) |
221 | 221 | //$users = TableRegistry::get('LdapConnections')->getListUsers(); |
222 | 222 | //sort($users); |
223 | - $users_name_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
224 | - $users_name = array_keys($users_name_and_email); | |
223 | + $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
224 | + $users_name = array_keys($users_login_and_email); | |
225 | 225 | // Formatage en $users_option_list["Etienne Pallier"] = "Etienne Pallier" ... |
226 | 226 | $users_option_list = []; |
227 | 227 | for ($i = 0; $i < sizeof($users_name); $i ++) { |
... | ... | @@ -237,7 +237,7 @@ class UsersController extends AppController |
237 | 237 | // "user" est l'utilisateur $user créé au début, et qui est vide |
238 | 238 | $this->set(compact('user', |
239 | 239 | 'groupesMetiers', |
240 | - 'users_option_list', 'users_name_and_email', | |
240 | + 'users_option_list', 'users_login_and_email', | |
241 | 241 | 'groupesThematiques', 'sur_categorie') |
242 | 242 | ); |
243 | 243 | $this->set('_serialize', [ | ... | ... |
src/Model/Table/LdapConnectionsTable.php
... | ... | @@ -276,14 +276,19 @@ class LdapConnectionsTable extends AppTable |
276 | 276 | // Sort users |
277 | 277 | //sort($u); |
278 | 278 | //debug($u); |
279 | + //var_dump($u[0]); | |
279 | 280 | // (EP) Refactorisation pour éviter code redondant ci-dessous, c'était pourtant pas compliqué, poil dans la main... |
280 | 281 | $nb_users = $this->LDAP_USED ? $u['count'] : sizeof($u)-1; |
281 | 282 | for ($i = 0; $i < $nb_users; $i ++) |
282 | 283 | // $utilisateurs["Pallier Etienne"] = ["email"] |
283 | - $usersWithNameAndEmail[ $u[$i]['sn'][0].' '.$u[$i]['givenname'][0] ] = $u[$i]['mail'][0]; | |
284 | - //debug($usersWithNameAndEmail); | |
284 | + ////$usersWithNameAndEmail[ $u[$i]['sn'][0].' '.$u[$i]['givenname'][0] ] = $u[$i]['mail'][0]; | |
285 | + $usersWithNameAndEmail[ $u[$i]['sn'][0].' '.$u[$i]['givenname'][0] ] = array( | |
286 | + "login" => $u[$i]['uid'][0], | |
287 | + "email" => $u[$i]['mail'][0] | |
288 | + ); | |
285 | 289 | // Sort users (without modifying the keys, don't use sort() but asort() !!!!!!!!!!!!!) |
286 | 290 | ksort($usersWithNameAndEmail); |
291 | + //debug($usersWithNameAndEmail); | |
287 | 292 | return $usersWithNameAndEmail; |
288 | 293 | } |
289 | 294 | ... | ... |
src/Template/Materiels/add.ctp
... | ... | @@ -5,11 +5,11 @@ |
5 | 5 | * Variables passed to this view by the Controller : |
6 | 6 | */ |
7 | 7 | $users_option_list = $users_option_list; |
8 | -$users_name_and_email = $users_name_and_email; | |
8 | +$users_login_and_email = $users_login_and_email; | |
9 | 9 | // TODO: yena d'autres... il faut les lister toutes ici, pour plus de clarté |
10 | 10 | |
11 | 11 | //debug($users_option_list); |
12 | -//debug($users_name_and_email); | |
12 | +//debug($users_login_and_email); | |
13 | 13 | |
14 | 14 | use Cake\ORM\TableRegistry; |
15 | 15 | if (isset($cpMateriel)) { |
... | ... | @@ -360,11 +360,11 @@ echo $this->element('menu_form', [ |
360 | 360 | |
361 | 361 | $(document).ready(function() { |
362 | 362 | |
363 | - // Convert (once for all) PHP $users_name_and_email array to JAVASCRIPT array | |
363 | + // Convert (once for all) PHP $users_login_and_email array to JAVASCRIPT array | |
364 | 364 | //Implode Method |
365 | 365 | //var array = [INF?php echo implode($array, ","); ?SUP]; |
366 | 366 | //JSON Method |
367 | - var users_name_and_email = <?php echo json_encode($users_name_and_email); ?>; | |
367 | + var users_login_and_email = <?php echo json_encode($users_login_and_email); ?>; | |
368 | 368 | |
369 | 369 | /** |
370 | 370 | * |
... | ... | @@ -412,13 +412,14 @@ $(document).ready(function() { |
412 | 412 | * |
413 | 413 | * Event "Nom utilisateur" change => "Email" change |
414 | 414 | * |
415 | - * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_name_and_email ??? | |
416 | - * (EP) New method, quicker, get email directly from PHP $users_name_and_email array | |
415 | + * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_login_and_email ??? | |
416 | + * (EP) New method, quicker, get email directly from PHP $users_login_and_email array | |
417 | 417 | * (OLD code is below, "fetch email via AJAX request to UsersController.getLdapEmail") |
418 | 418 | */ |
419 | 419 | $("#nom-responsable").bind("change", function(event) { |
420 | 420 | var nom_resp = $("#nom-responsable").val(); |
421 | - var new_email = users_name_and_email[nom_resp]; | |
421 | + //var new_email = users_login_and_email[nom_resp]; | |
422 | + var new_email = users_login_and_email[nom_resp]["email"]; | |
422 | 423 | $("#email-responsable").val(new_email); |
423 | 424 | }); |
424 | 425 | ... | ... |
src/Template/Materiels/edit.ctp
... | ... | @@ -6,11 +6,11 @@ |
6 | 6 | * Variables passed to this view by the Controller : |
7 | 7 | */ |
8 | 8 | $users_option_list = $users_option_list; |
9 | -$users_name_and_email = $users_name_and_email; | |
9 | +$users_login_and_email = $users_login_and_email; | |
10 | 10 | // TODO: yena d'autres... il faut les lister toutes ici, pour plus de clarté |
11 | 11 | |
12 | 12 | //debug($users_option_list); |
13 | -//debug($users_name_and_email); | |
13 | +//debug($users_login_and_email); | |
14 | 14 | |
15 | 15 | |
16 | 16 | use Cake\ORM\TableRegistry; |
... | ... | @@ -463,11 +463,11 @@ echo $this->element('menu_form', [ |
463 | 463 | |
464 | 464 | $(document).ready(function () { |
465 | 465 | |
466 | - // Convert (once for all) PHP $users_name_and_email array to JAVASCRIPT array | |
466 | + // Convert (once for all) PHP $users_login_and_email array to JAVASCRIPT array | |
467 | 467 | //Implode Method |
468 | 468 | //var array = [INF?php echo implode($array, ","); ?SUP]; |
469 | 469 | //JSON Method |
470 | - var users_name_and_email = <?php echo json_encode($users_name_and_email); ?>; | |
470 | + var users_login_and_email = <?php echo json_encode($users_login_and_email); ?>; | |
471 | 471 | |
472 | 472 | /** |
473 | 473 | * Event DOMAINE change |
... | ... | @@ -530,13 +530,14 @@ $(document).ready(function () { |
530 | 530 | * |
531 | 531 | * Event "Nom utilisateur" change => "Email" change |
532 | 532 | * |
533 | - * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_name_and_email ??? | |
534 | - * (EP) New method, quicker, get email directly from PHP $users_name_and_email array | |
533 | + * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_login_and_email ??? | |
534 | + * (EP) New method, quicker, get email directly from PHP $users_login_and_email array | |
535 | 535 | * (OLD code is below (at the end), "fetch email via AJAX request to UsersController.getLdapEmail") |
536 | 536 | */ |
537 | 537 | $("#nom-responsable").bind("change", function(event) { |
538 | 538 | var nom_resp = $("#nom-responsable").val(); |
539 | - var new_email = users_name_and_email[nom_resp]; | |
539 | + //var new_email = users_login_and_email[nom_resp]; | |
540 | + var new_email = users_login_and_email[nom_resp]["email"]; | |
540 | 541 | $("#email-responsable").val(new_email); |
541 | 542 | }); |
542 | 543 | ... | ... |
src/Template/Users/add.ctp
1 | 1 | |
2 | 2 | <?php |
3 | 3 | //var_dump($users_option_list); |
4 | -//var_dump($users_name_and_email); | |
4 | +//var_dump($users_login_and_email); | |
5 | 5 | |
6 | 6 | /* |
7 | 7 | * (EP) |
8 | 8 | * Variables passed to this view by the Controller : |
9 | 9 | */ |
10 | 10 | $users_option_list = $users_option_list; |
11 | -$users_name_and_email = $users_name_and_email; | |
11 | +$users_login_and_email = $users_login_and_email; | |
12 | 12 | // TODO: yena d'autres... il faut les lister toutes ici, pour plus de clarté |
13 | 13 | |
14 | 14 | |
... | ... | @@ -32,6 +32,7 @@ $users_name_and_email = $users_name_and_email; |
32 | 32 | 'div' => 'input required' |
33 | 33 | ]); |
34 | 34 | } |
35 | + | |
35 | 36 | // fake LDAP |
36 | 37 | else { |
37 | 38 | echo $this->Form->control('newname', [ |
... | ... | @@ -114,21 +115,21 @@ if ($LDAP_USED) { |
114 | 115 | /** |
115 | 116 | * Quand on selectionne un utilisateur dans la liste => on met à jour son login et son email (en readonly) |
116 | 117 | |
117 | - * (EP 6/5/19) New method, quicker, get email directly from PHP $users_name_and_email array | |
118 | + * (EP 6/5/19) New method, quicker, get email directly from PHP $users_login_and_email array | |
118 | 119 | * (OLD code is at end of file) |
119 | 120 | * |
120 | 121 | * Event "Nom utilisateur" change => "login" and "email" change |
121 | 122 | * |
122 | - * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_name_and_email ??? | |
123 | + * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_login_and_email ??? | |
123 | 124 | */ |
124 | 125 | |
125 | 126 | $(document).ready(function () { |
126 | 127 | |
127 | - // Convert (once for all) PHP $users_name_and_email array to JAVASCRIPT array | |
128 | + // Convert (once for all) PHP $users_login_and_email array to JAVASCRIPT array | |
128 | 129 | //Implode Method |
129 | 130 | //var array = [INF?php echo implode($array, ","); ?SUP]; |
130 | 131 | //JSON Method |
131 | - var users_name_and_email = <?php echo json_encode($users_name_and_email); ?>; | |
132 | + var users_login_and_email = <?php echo json_encode($users_login_and_email); ?>; | |
132 | 133 | |
133 | 134 | |
134 | 135 | $("#nom").bind("change", function(event) { |
... | ... | @@ -137,16 +138,11 @@ $(document).ready(function () { |
137 | 138 | var user_name = $("#nom").val(); |
138 | 139 | |
139 | 140 | /* Mise a jour du login */ |
140 | - var url = document.URL; | |
141 | - var loginUrl = url.replace("add", "getLdapLogin/"); | |
142 | - $.ajax({ | |
143 | - url: loginUrl + $("#nom").val() | |
144 | - }).done(function(data) { | |
145 | - $("#username").val(data) | |
146 | - }); | |
141 | + var new_login = users_login_and_email[user_name]["login"]; | |
142 | + $("#username").val(new_login); | |
147 | 143 | |
148 | 144 | /* Mise a jour du mail */ |
149 | - var new_email = users_name_and_email[user_name]; | |
145 | + var new_email = users_login_and_email[user_name]["email"]; | |
150 | 146 | $("#email").val(new_email); |
151 | 147 | |
152 | 148 | }); // ON "nom" field change | ... | ... |