public function actionAuthenticationLdap()
 {
     $form = new \humhub\modules\admin\models\forms\AuthenticationLdapSettingsForm();
     if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
         Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved'));
         return $this->redirect(['/admin/authentication/authentication-ldap']);
     }
     $enabled = false;
     $userCount = 0;
     $errorMessage = "";
     if (Yii::$app->getModule('user')->settings->get('auth.ldap.enabled')) {
         $enabled = true;
         try {
             $ldapAuthClient = new \humhub\modules\user\authclient\ZendLdapClient();
             $ldap = $ldapAuthClient->getLdap();
             $userCount = $ldap->count(Yii::$app->getModule('user')->settings->get('auth.ldap.userFilter'), Yii::$app->getModule('user')->settings->get('auth.ldap.baseDn'), \Zend\Ldap\Ldap::SEARCH_SCOPE_SUB);
         } catch (\Zend\Ldap\Exception\LdapException $ex) {
             $errorMessage = $ex->getMessage();
         } catch (\Exception $ex) {
             $errorMessage = $ex->getMessage();
         }
     }
     return $this->render('authentication_ldap', array('model' => $form, 'enabled' => $enabled, 'userCount' => $userCount, 'errorMessage' => $errorMessage));
 }
Пример #2
0
 /**
  * Returns a List of Users
  */
 public function actionAuthenticationLdap()
 {
     $form = new \humhub\modules\admin\models\forms\AuthenticationLdapSettingsForm();
     // Load Defaults
     $form->enabled = Setting::Get('enabled', 'authentication_ldap');
     $form->refreshUsers = Setting::Get('refreshUsers', 'authentication_ldap');
     $form->username = Setting::Get('username', 'authentication_ldap');
     $form->password = Setting::Get('password', 'authentication_ldap');
     $form->hostname = Setting::Get('hostname', 'authentication_ldap');
     $form->port = Setting::Get('port', 'authentication_ldap');
     $form->encryption = Setting::Get('encryption', 'authentication_ldap');
     $form->baseDn = Setting::Get('baseDn', 'authentication_ldap');
     $form->loginFilter = Setting::Get('loginFilter', 'authentication_ldap');
     $form->userFilter = Setting::Get('userFilter', 'authentication_ldap');
     $form->usernameAttribute = Setting::Get('usernameAttribute', 'authentication_ldap');
     $form->emailAttribute = Setting::Get('emailAttribute', 'authentication_ldap');
     if ($form->password != '') {
         $form->password = '******';
     }
     if ($form->load(Yii::$app->request->post()) && $form->validate()) {
         Setting::Set('enabled', $form->enabled, 'authentication_ldap');
         Setting::Set('refreshUsers', $form->refreshUsers, 'authentication_ldap');
         Setting::Set('hostname', $form->hostname, 'authentication_ldap');
         Setting::Set('port', $form->port, 'authentication_ldap');
         Setting::Set('encryption', $form->encryption, 'authentication_ldap');
         Setting::Set('username', $form->username, 'authentication_ldap');
         if ($form->password != '---hidden---') {
             Setting::Set('password', $form->password, 'authentication_ldap');
         }
         Setting::Set('baseDn', $form->baseDn, 'authentication_ldap');
         Setting::Set('loginFilter', $form->loginFilter, 'authentication_ldap');
         Setting::Set('userFilter', $form->userFilter, 'authentication_ldap');
         Setting::Set('usernameAttribute', $form->usernameAttribute, 'authentication_ldap');
         Setting::Set('emailAttribute', $form->emailAttribute, 'authentication_ldap');
         // set flash message
         Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved'));
         Yii::$app->response->redirect(Url::toRoute('/admin/setting/authentication-ldap'));
     }
     $enabled = false;
     $userCount = 0;
     $errorMessage = "";
     if (Setting::Get('enabled', 'authentication_ldap')) {
         $enabled = true;
         try {
             if (Ldap::getInstance()->ldap !== null) {
                 $userCount = Ldap::getInstance()->ldap->count(Setting::Get('userFilter', 'authentication_ldap'), Setting::Get('baseDn', 'authentication_ldap'), \Zend\Ldap\Ldap::SEARCH_SCOPE_SUB);
             } else {
                 $errorMessage = Yii::t('AdminModule.controllers_SettingController', 'Could not load LDAP! - Check PHP Extension');
             }
         } catch (\Zend\Ldap\Exception\LdapException $ex) {
             $errorMessage = $ex->getMessage();
         } catch (Exception $ex) {
             $errorMessage = $ex->getMessage();
         }
     }
     return $this->render('authentication_ldap', array('model' => $form, 'enabled' => $enabled, 'userCount' => $userCount, 'errorMessage' => $errorMessage));
 }