diff --git a/model/user.php b/model/user.php index d2b2cc5..ba9290b 100644 --- a/model/user.php +++ b/model/user.php @@ -295,10 +295,11 @@ class User extends Entity { /** * Retrieve the user's details from LDAP. + * @param bool $login true if getting user details as part of login process * @throws UserNotFoundException if the user is not found in LDAP */ - public function get_details_from_ldap() { - global $config, $group_dir, $user_dir; + public function get_details_from_ldap($login = false) { + global $config, $group_dir, $user_dir, $active_user; $attributes = array(); $attributes[] = 'dn'; $attributes[] = $config['ldap']['user_id']; @@ -345,6 +346,9 @@ class User extends Entity { $this->update(); } else { $user_dir->add_user($this); + if($login) { + $active_user = $this; + } } if(isset($config['ldap']['sync_groups']) && is_array($config['ldap']['sync_groups'])) { $syncgroups = $config['ldap']['sync_groups']; diff --git a/model/userdirectory.php b/model/userdirectory.php index dee049f..e4de782 100644 --- a/model/userdirectory.php +++ b/model/userdirectory.php @@ -78,10 +78,11 @@ class UserDirectory extends DBDirectory { * Get a user from the database by its uid. If it does not exist in the database, retrieve it * from LDAP and store in the database. * @param string $uid of user + * @param bool $login true if getting user as part of login process * @return User with specified entity uid * @throws UserNotFoundException if no user with that uid exists */ - public function get_user_by_uid($uid) { + public function get_user_by_uid($uid, $login = false) { if(isset($this->cache_uid[$uid])) { return $this->cache_uid[$uid]; } @@ -96,7 +97,7 @@ class UserDirectory extends DBDirectory { $user = new User; $user->uid = $uid; $this->cache_uid[$uid] = $user; - $user->get_details_from_ldap(); + $user->get_details_from_ldap($login); } $stmt->close(); return $user; diff --git a/requesthandler.php b/requesthandler.php index cc31e82..bd8e3ea 100644 --- a/requesthandler.php +++ b/requesthandler.php @@ -21,7 +21,7 @@ ob_start(); set_exception_handler('exception_handler'); if(isset($_SERVER['PHP_AUTH_USER'])) { - $active_user = $user_dir->get_user_by_uid($_SERVER['PHP_AUTH_USER']); + $active_user = $user_dir->get_user_by_uid($_SERVER['PHP_AUTH_USER'], true); } else { throw new Exception("Not logged in."); }