Commit be8d153182756ac4722a6a7b538c966fd48e0fb6
1 parent
091b1d3d
Exists in
master
and in
2 other branches
encore un petit bugfix
Showing
4 changed files
with
48 additions
and
29 deletions
Show diff stats
README.md
... | ... | @@ -54,12 +54,11 @@ Logiciel testé et validé sur les configurations suivantes : |
54 | 54 | VERSION ACTUELLE |
55 | 55 | |
56 | 56 | Date: 14/02/2019 |
57 | -Version: 2.10.12.bugfix5 | |
57 | +Version: 2.10.13.bugfix1 | |
58 | 58 | Author: EP |
59 | - (version IRAP only) Bugfix LDAP anonyme, refactorisation, et optimisation | |
59 | + (IRAP ONLY) Bugfix Ajout/Edit materiel | |
60 | 60 | |
61 | - - LDAP anonyme se faisait sans vérifier le mot de passe utilisateur !!! | |
62 | - - Optimisation update email sur changement de responsable (dans vues ADD et EDIT) => LDAP et AJAX inutile, on fait avec un tableau local | |
61 | + LDAP refactorisation && optimisation (1) | |
63 | 62 | |
64 | 63 | IMPORTANT: |
65 | 64 | - Pour connaitre la version actuelle, taper "./VERSION" |
... | ... | @@ -81,9 +80,6 @@ Version majeure en cours : 2.10 (https://projects.irap.omp.eu/versions/207) |
81 | 80 | ROADMAP: https://projects.irap.omp.eu/projects/inventirap/roadmap |
82 | 81 | |
83 | 82 | |
84 | -(+ en cours: | |
85 | - Ajout du dossier vendor/ dans git (évite d'avoir besoin de réinstaller les dépendances à chaque update de cakephp) | |
86 | -) | |
87 | 83 | ----------------------------------------------------------------------------------------------------------- |
88 | 84 | Messages à copier/coller en cas de besoin : |
89 | 85 | - ATTENTION : Mise à jour de la base de données requise (cf database/update) | ... | ... |
src/Controller/MaterielsController.php
... | ... | @@ -794,7 +794,7 @@ class MaterielsController extends AppController |
794 | 794 | 'order' => 'designation', |
795 | 795 | 'group' => 'designation' |
796 | 796 | ]); |
797 | - $domaineresp = TableRegistry::get('Users')->find() | |
797 | + $domaineresp = TableRegistry::getTableLocator()->get('Users')->find() | |
798 | 798 | ->select('sur_categorie_id') |
799 | 799 | ->where([ |
800 | 800 | 'username =' => $this->LdapAuth->user($this->request->getSession() |
... | ... | @@ -803,8 +803,8 @@ class MaterielsController extends AppController |
803 | 803 | ->first()['sur_categorie_id']; |
804 | 804 | if ($domaineresp == null) |
805 | 805 | $domaineresp = false; |
806 | - $utilisateurconnect = TableRegistry::get('Users')->find('all')->toArray(); | |
807 | - | |
806 | + $utilisateurconnect = TableRegistry::getTableLocator()->get('Users')->find('all')->toArray(); | |
807 | + | |
808 | 808 | // TODO: code redondant avec edit(), à factoriser |
809 | 809 | // HOWTO: https://book.cakephp.org/3.0/en/orm.html |
810 | 810 | //$users = TableRegistry::get('LdapConnections')->getListUsers(); |
... | ... | @@ -1132,7 +1132,7 @@ class MaterielsController extends AppController |
1132 | 1132 | 'order' => 'Fournisseurs.nom' |
1133 | 1133 | ]); |
1134 | 1134 | |
1135 | - $users = TableRegistry::get('LdapConnections')->getListUsers(); | |
1135 | + $users = TableRegistry::getTableLocator()->get('LdapConnections')->getListUsers(); | |
1136 | 1136 | |
1137 | 1137 | // tri des utilisateurs par nom |
1138 | 1138 | sort($users); | ... | ... |
src/Controller/UsersController.php
... | ... | @@ -61,20 +61,22 @@ class UsersController extends AppController |
61 | 61 | return parent::isAuthorized($user); |
62 | 62 | } |
63 | 63 | |
64 | - /* | |
65 | - // Utilisateur identifie | |
66 | - //debug($user); | |
67 | - // On va maintenant à la page qui etait demandee | |
68 | - // Utilisateur non reconnu | |
69 | - */ | |
70 | 64 | public function login() |
71 | 65 | { |
66 | + // Un utilisateur a essayé de se loguer | |
72 | 67 | if ($this->request->is('post')) { |
73 | 68 | $user = $this->LdapAuth->connection(); |
69 | + //var_dump($user); | |
70 | + //debug($user); | |
71 | + | |
72 | + // Le login a été accepté | |
74 | 73 | if ($user != FALSE) { |
75 | 74 | $this->LdapAuth->setUser($user); |
75 | + // On va maintenant à la page qui etait demandee | |
76 | 76 | return $this->redirect($this->LdapAuth->redirectUrl()); |
77 | 77 | } |
78 | + | |
79 | + // Utilisateur non reconnu | |
78 | 80 | $this->Flash->error(__('Login ou mot de passe invalide, réessayez')); |
79 | 81 | } |
80 | 82 | } | ... | ... |
src/Model/Table/LdapConnectionsTable.php
... | ... | @@ -29,7 +29,7 @@ class LdapConnectionsTable extends AppTable |
29 | 29 | private $bindPass; |
30 | 30 | /* fin MCM*/ |
31 | 31 | |
32 | - private $USE_LDAP = TRUE; | |
32 | + private $LDAP_USED = TRUE; | |
33 | 33 | |
34 | 34 | private $fakeLDAPUsers = []; |
35 | 35 | |
... | ... | @@ -47,7 +47,7 @@ class LdapConnectionsTable extends AppTable |
47 | 47 | public function useLdap() |
48 | 48 | { |
49 | 49 | $this->checkConfiguration(); |
50 | - return $this->USE_LDAP; | |
50 | + return $this->LDAP_USED; | |
51 | 51 | } |
52 | 52 | |
53 | 53 | private function buildFakeLdapUsers() |
... | ... | @@ -140,10 +140,10 @@ class LdapConnectionsTable extends AppTable |
140 | 140 | ]) |
141 | 141 | ->first(); |
142 | 142 | |
143 | - //$this->USE_LDAP = $config->use_ldap ? TRUE : FALSE; | |
144 | - $this->USE_LDAP = $config->ldap_used; | |
143 | + //$this->LDAP_USED = $config->LDAP_USED ? TRUE : FALSE; | |
144 | + $this->LDAP_USED = $config->ldap_used; | |
145 | 145 | |
146 | - if (! $this->USE_LDAP) { | |
146 | + if (! $this->LDAP_USED) { | |
147 | 147 | //$this->authenticationType = $config->authentificationType_ldap; |
148 | 148 | $this->authenticationType = $config->ldap_authenticationType; |
149 | 149 | if (empty($this->fakeLDAPUsers)) |
... | ... | @@ -190,7 +190,7 @@ class LdapConnectionsTable extends AppTable |
190 | 190 | try { |
191 | 191 | if ($this->checkConfiguration()) { |
192 | 192 | // REAL LDAP |
193 | - if ($this->USE_LDAP) { | |
193 | + if ($this->LDAP_USED) { | |
194 | 194 | $ldapConnection = ldap_connect($this->host, $this->port); |
195 | 195 | ldap_set_option($ldapConnection, LDAP_OPT_PROTOCOL_VERSION, 3); |
196 | 196 | |
... | ... | @@ -213,7 +213,7 @@ class LdapConnectionsTable extends AppTable |
213 | 213 | try { |
214 | 214 | |
215 | 215 | if ($this->checkConfiguration()) { |
216 | - if ($this->USE_LDAP) { | |
216 | + if ($this->LDAP_USED) { | |
217 | 217 | $ldapConnection = ldap_connect($this->host, $this->port); |
218 | 218 | ldap_set_option($ldapConnection, LDAP_OPT_PROTOCOL_VERSION, 3); |
219 | 219 | $results = ldap_search($ldapConnection, $this->baseDn, '(' . $this->authenticationType . '=' . $userName . ')'); |
... | ... | @@ -244,6 +244,27 @@ class LdapConnectionsTable extends AppTable |
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
247 | + * Return a list of Users with key = username & value = email | |
248 | + */ | |
249 | + public function getUsersWithNameAndEmail() { | |
250 | + $usersWithNameAndEmail = []; | |
251 | + // Get all users (with ALL their attributes) | |
252 | + $u = $this->getAllLdapUsers(); | |
253 | + // Sort users | |
254 | + //sort($u); | |
255 | + //debug($u); | |
256 | + // (EP) Refactorisation pour éviter code redondant ci-dessous, c'était pourtant pas compliqué, poil dans la main... | |
257 | + $nb_users = $this->LDAP_USED ? $u['count'] : sizeof($u)-1; | |
258 | + for ($i = 0; $i < $nb_users; $i ++) | |
259 | + // $utilisateurs["Pallier Etienne"] = ["email"] | |
260 | + $usersWithNameAndEmail[ $u[$i]['sn'][0].' '.$u[$i]['givenname'][0] ] = $u[$i]['mail'][0]; | |
261 | + //debug($usersWithNameAndEmail); | |
262 | + // Sort users (without modifying the keys, don't use sort() but asort() !!!!!!!!!!!!!) | |
263 | + ksort($usersWithNameAndEmail); | |
264 | + return $usersWithNameAndEmail; | |
265 | + } | |
266 | + | |
267 | + /** | |
247 | 268 | * Return a list of Users with key = username & value = username |
248 | 269 | */ |
249 | 270 | public function getListUsers() |
... | ... | @@ -251,7 +272,7 @@ class LdapConnectionsTable extends AppTable |
251 | 272 | $u = $this->getAllLdapUsers(); |
252 | 273 | $utilisateurs = []; |
253 | 274 | |
254 | - if ($this->USE_LDAP) { | |
275 | + if ($this->LDAP_USED) { | |
255 | 276 | for ($i = 0; $i < $u['count']; $i ++) { |
256 | 277 | $utilisateurs[$u[$i]['sn'][0] . ' ' . $u[$i]['givenname'][0]] = $u[$i]['sn'][0] . ' ' . $u[$i]['givenname'][0]; |
257 | 278 | } |
... | ... | @@ -272,7 +293,7 @@ class LdapConnectionsTable extends AppTable |
272 | 293 | $u = $this->getAllLdapUsers(); |
273 | 294 | $utilisateurs = []; |
274 | 295 | |
275 | - if ($this->USE_LDAP) { | |
296 | + if ($this->LDAP_USED) { | |
276 | 297 | for ($i = 0; $i < $u['count']; $i ++) { |
277 | 298 | $utilisateurs[$u[$i]['sn'][0] . ' ' . $u[$i]['givenname'][0]] = $u[$i][$this->authenticationType][0]; |
278 | 299 | } |
... | ... | @@ -293,7 +314,7 @@ class LdapConnectionsTable extends AppTable |
293 | 314 | $u = $this->getAllLdapUsers(); |
294 | 315 | $utilisateurs = []; |
295 | 316 | |
296 | - if ($this->USE_LDAP) { | |
317 | + if ($this->LDAP_USED) { | |
297 | 318 | for ($i = 0; $i < $u['count']; $i ++) { |
298 | 319 | if (isset($u[$i]['mail'][0])) { |
299 | 320 | $utilisateurs[$u[$i]['sn'][0] . ' ' . $u[$i]['givenname'][0]] = $u[$i]['mail'][0]; |
... | ... | @@ -317,7 +338,7 @@ class LdapConnectionsTable extends AppTable |
317 | 338 | { |
318 | 339 | $u = $this->getAllLdapUsers(); |
319 | 340 | |
320 | - if ($this->USE_LDAP) { | |
341 | + if ($this->LDAP_USED) { | |
321 | 342 | $nbUsers = $u['count']; |
322 | 343 | } else { |
323 | 344 | $nbUsers = sizeof($u) - 1; |
... | ... | @@ -340,7 +361,7 @@ class LdapConnectionsTable extends AppTable |
340 | 361 | try { |
341 | 362 | if ($this->checkConfiguration()) { |
342 | 363 | |
343 | - if ($this->USE_LDAP) { | |
364 | + if ($this->LDAP_USED) { | |
344 | 365 | if (strlen(trim($password)) == 0) |
345 | 366 | return FALSE; |
346 | 367 | $ldapConnection = ldap_connect($this->host, $this->port); | ... | ... |