diff options
-rw-r--r-- | app/Auth/Ldap.php | 20 | ||||
-rw-r--r-- | jsonrpc.php | 11 |
2 files changed, 18 insertions, 13 deletions
diff --git a/app/Auth/Ldap.php b/app/Auth/Ldap.php index 22c9fb88..dbf12387 100644 --- a/app/Auth/Ldap.php +++ b/app/Auth/Ldap.php @@ -208,27 +208,31 @@ class Ldap extends Base } /** - * Retrieve info on LDAP user. + * Retrieve info on LDAP user * - * @param resource $ldap LDAP connection * @param string $username Username * @param string $email Email address */ public function lookup($username = null, $email = null) { - if ($username && $email) + if ($username && $email) { $query = '(&('.sprintf(LDAP_USER_PATTERN, $username).')('.sprintf(LDAP_ACCOUNT_EMAIL, $email).')'; - else if ($username) + } + else if ($username) { $query = sprintf(LDAP_USER_PATTERN, $username); - else if ($email) + } + else if ($email) { $query = '('.LDAP_ACCOUNT_EMAIL.'='.$email.')'; - else + } + else { return false; + } // Connect and attempt anonymous bind $ldap = $this->connect(); - if (!is_resource($ldap) || !$this->bind($ldap, null, null)) + if (! is_resource($ldap) || ! $this->bind($ldap, null, null)) { return false; + } // Try to find user $sr = @ldap_search($ldap, LDAP_ACCOUNT_BASE, $query, array(LDAP_ACCOUNT_FULLNAME, LDAP_ACCOUNT_EMAIL, LDAP_ACCOUNT_ID)); @@ -244,7 +248,7 @@ class Ldap extends Base } // User id not retrieved: LDAP_ACCOUNT_ID not properly configured - if (!$username && !isset($info[0][LDAP_ACCOUNT_ID][0])) { + if (! $username && ! isset($info[0][LDAP_ACCOUNT_ID][0])) { return false; } diff --git a/jsonrpc.php b/jsonrpc.php index 3de9de1b..0b71af10 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -160,15 +160,16 @@ $server->register('createUser', function($username, $password, $name = '', $emai $server->register('createLdapUser', function($username = '', $email = '', $is_admin = 0, $default_project_id = 0) use ($container) { $ldap = new Auth\Ldap($container); - $res = $ldap->lookup($username, $email); + $user = $ldap->lookup($username, $email); - if (!$res) + if (! $user) { return false; + } $values = array( - 'username' => $res['username'], - 'name' => $res['name'], - 'email' => $res['email'], + 'username' => $user['username'], + 'name' => $user['name'], + 'email' => $user['email'], 'is_ldap_user' => 1, 'is_admin' => $is_admin, 'default_project_id' => $default_project_id, |