Fixed #1668: Missing import of LDAP exception

This commit is contained in:
Lucas Bartholemy 2016-05-01 19:24:38 +02:00
parent aad2063e6c
commit 5b4373aba1

View File

@ -2,7 +2,7 @@
/** /**
* @link https://www.humhub.org/ * @link https://www.humhub.org/
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG * @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences * @license https://www.humhub.com/licences
*/ */
@ -103,14 +103,14 @@ class Ldap extends \yii\base\Component
$this->ldap->bind($username, $password); $this->ldap->bind($username, $password);
// disconnect id needed here because otherwise binding/ldap connection again can cause errors. // disconnect id needed here because otherwise binding/ldap connection again can cause errors.
$this->ldap->disconnect(); $this->ldap->disconnect();
// Update Users Data // Update Users Data
$node = $this->ldap->getNode($username); $node = $this->ldap->getNode($username);
$this->handleLdapUser($node); $this->handleLdapUser($node);
return true; return true;
} catch (\Zend\Ldap\Exception\LdapException $ex) { } catch (\Zend\Ldap\Exception\LdapException $ex) {
// log errors other than invalid credentials // log errors other than invalid credentials
if ($ex->getCode() !== LdapException::LDAP_INVALID_CREDENTIALS) { if ($ex->getCode() !== \Zend\Ldap\Exception\LdapException::LDAP_INVALID_CREDENTIALS) {
Yii::error('LDAP Error: ' . $ex->getMessage()); Yii::error('LDAP Error: ' . $ex->getMessage());
} }
return false; return false;
@ -144,7 +144,7 @@ class Ldap extends \yii\base\Component
foreach (User::find()->where(['auth_mode' => User::AUTH_MODE_LDAP])->each() as $user) { foreach (User::find()->where(['auth_mode' => User::AUTH_MODE_LDAP])->each() as $user) {
if (!in_array($user->id, $ldapUserIds)) { if (!in_array($user->id, $ldapUserIds)) {
if($user->status != User::STATUS_DISABLED) { if ($user->status != User::STATUS_DISABLED) {
// User no longer available in ldap // User no longer available in ldap
$user->status = User::STATUS_DISABLED; $user->status = User::STATUS_DISABLED;
\humhub\modules\user\models\Setting::Set($user->id, 'disabled_by_ldap', true, 'user'); \humhub\modules\user\models\Setting::Set($user->id, 'disabled_by_ldap', true, 'user');
@ -152,7 +152,7 @@ class Ldap extends \yii\base\Component
Yii::warning('Disabled user ' . $user->username . ' (' . $user->id . ') - Not found in LDAP!'); Yii::warning('Disabled user ' . $user->username . ' (' . $user->id . ') - Not found in LDAP!');
} }
} else { } else {
if($user->status == User::STATUS_DISABLED && \humhub\modules\user\models\Setting::Get($user->id, 'disabled_by_ldap', 'user', false)) { if ($user->status == User::STATUS_DISABLED && \humhub\modules\user\models\Setting::Get($user->id, 'disabled_by_ldap', 'user', false)) {
// User no longer available in ldap // User no longer available in ldap
$user->status = User::STATUS_ENABLED; $user->status = User::STATUS_ENABLED;
\humhub\modules\user\models\Setting::Set($user->id, 'disabled_by_ldap', '', 'user'); \humhub\modules\user\models\Setting::Set($user->id, 'disabled_by_ldap', '', 'user');