From 2baa69fe34ce30abe1ddff5ecc157e2008ded609 Mon Sep 17 00:00:00 2001 From: Morph01 Date: Tue, 4 Feb 2025 14:51:10 -0800 Subject: [PATCH] feat: add user details --- models/LDAPAuth.php | 29 +++++++++++++++++++++++++++++ views/menu.php | 22 ++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/models/LDAPAuth.php b/models/LDAPAuth.php index 333e535..10ef257 100644 --- a/models/LDAPAuth.php +++ b/models/LDAPAuth.php @@ -330,4 +330,33 @@ class LDAPAuth return $users; } + + public function getUserDetails($username) + { + $this->connect(); + $this->bindServiceAccount(); + + $filter = "(sAMAccountName=$username)"; + $attributes = ["*"]; // Récupère tous les attributs + + $result = ldap_search($this->ad, "DC=epul3a,DC=local", $filter, $attributes); + $entries = ldap_get_entries($this->ad, $result); + + if ($entries['count'] > 0) { + return $this->cleanLdapEntries($entries[0]); + } + + return []; + } + + private function cleanLdapEntries($entry) + { + $clean = []; + foreach ($entry as $key => $value) { + if (!is_numeric($key) && is_array($value)) { + $clean[$key] = $value[0]; + } + } + return $clean; + } } diff --git a/views/menu.php b/views/menu.php index 09f3e6a..9016c78 100644 --- a/views/menu.php +++ b/views/menu.php @@ -19,8 +19,8 @@ echo "Bienvenue " . $_SESSION["sAMAccountName"] . "!"; echo "

Menu

"; echo "