Skip to content

Commit

Permalink
Set $active_user immediately after creating user when logging in for …
Browse files Browse the repository at this point in the history
…first time

Relates to: #55
  • Loading branch information
thomas-pike committed Nov 7, 2021
1 parent a5a1f7c commit 4641ce0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions model/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,11 @@ public function check_csrf_token($token) {

/**
* 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'];
Expand Down Expand Up @@ -345,6 +346,9 @@ public function get_details_from_ldap() {
$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'];
Expand Down
5 changes: 3 additions & 2 deletions model/userdirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ public function get_user_by_id($id) {
* 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];
}
Expand All @@ -96,7 +97,7 @@ public function get_user_by_uid($uid) {
$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;
Expand Down
2 changes: 1 addition & 1 deletion requesthandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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.");
}
Expand Down

0 comments on commit 4641ce0

Please sign in to comment.