mirror of
https://github.com/humhub/humhub.git
synced 2025-02-24 03:06:04 +01:00
Merge pull request #2920 from danielkesselberg/phpdoc-codestyle-authentication
CodeStyle for AuthenticationController & View
This commit is contained in:
commit
64b5e4c1b2
@ -1,15 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\admin\controllers;
|
||||
|
||||
use Yii;
|
||||
use Exception;
|
||||
use humhub\modules\admin\components\Controller;
|
||||
use humhub\modules\admin\models\forms\AuthenticationLdapSettingsForm;
|
||||
use humhub\modules\admin\models\forms\AuthenticationSettingsForm;
|
||||
use humhub\modules\admin\permissions\ManageSettings;
|
||||
use humhub\modules\user\authclient\ZendLdapClient;
|
||||
use humhub\modules\user\libs\LdapHelper;
|
||||
use humhub\modules\user\models\Group;
|
||||
use Yii;
|
||||
use Zend\Ldap\Exception\LdapException;
|
||||
use Zend\Ldap\Ldap;
|
||||
|
||||
/**
|
||||
* ApprovalController handels new user approvals
|
||||
@ -34,8 +42,8 @@ class AuthenticationController extends Controller
|
||||
]);
|
||||
|
||||
$this->subLayout = '@admin/views/layouts/user';
|
||||
|
||||
return parent::init();
|
||||
|
||||
return parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,38 +52,48 @@ class AuthenticationController extends Controller
|
||||
public function getAccessRules()
|
||||
{
|
||||
return [
|
||||
['permissions' => \humhub\modules\admin\permissions\ManageSettings::className()]
|
||||
['permissions' => ManageSettings::className()]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List of Users
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$form = new \humhub\modules\admin\models\forms\AuthenticationSettingsForm;
|
||||
$form = new AuthenticationSettingsForm;
|
||||
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
|
||||
$this->view->saved();
|
||||
}
|
||||
|
||||
// Build Group Dropdown
|
||||
$groups = [];
|
||||
$groups[''] = Yii::t('AdminModule.controllers_SettingController', 'None - shows dropdown in user registration.');
|
||||
foreach (\humhub\modules\user\models\Group::find()->all() as $group) {
|
||||
$groups = [
|
||||
'' => Yii::t(
|
||||
'AdminModule.controllers_SettingController',
|
||||
'None - shows dropdown in user registration.'
|
||||
)
|
||||
];
|
||||
|
||||
foreach (Group::find()->all() as $group) {
|
||||
if (!$group->is_admin_group) {
|
||||
$groups[$group->id] = $group->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('authentication', [
|
||||
'model' => $form,
|
||||
'groups' => $groups
|
||||
]);
|
||||
'model' => $form,
|
||||
'groups' => $groups
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Ldap authentication
|
||||
* @return string
|
||||
*/
|
||||
public function actionAuthenticationLdap()
|
||||
{
|
||||
$form = new \humhub\modules\admin\models\forms\AuthenticationLdapSettingsForm;
|
||||
$form = new AuthenticationLdapSettingsForm;
|
||||
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
|
||||
$this->view->saved();
|
||||
return $this->redirect(['/admin/authentication/authentication-ldap']);
|
||||
@ -88,16 +106,16 @@ class AuthenticationController extends Controller
|
||||
if (Yii::$app->getModule('user')->settings->get('auth.ldap.enabled')) {
|
||||
$enabled = true;
|
||||
try {
|
||||
$ldapAuthClient = new \humhub\modules\user\authclient\ZendLdapClient();
|
||||
$ldapAuthClient = new 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
|
||||
Ldap::SEARCH_SCOPE_SUB
|
||||
);
|
||||
} catch (\Zend\Ldap\Exception\LdapException $ex) {
|
||||
} catch (LdapException $ex) {
|
||||
$errorMessage = $ex->getMessage();
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$errorMessage = $ex->getMessage();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var $this \yii\web\View
|
||||
* @var $enabled boolean
|
||||
@ -7,50 +6,86 @@
|
||||
* @var $model \humhub\modules\admin\models\forms\AuthenticationLdapSettingsForm
|
||||
* @var $userCount string
|
||||
*/
|
||||
|
||||
use humhub\models\Setting;
|
||||
use humhub\widgets\DataSaved;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
?>
|
||||
|
||||
<?php $this->beginContent('@admin/views/authentication/_authenticationLayout.php') ?>
|
||||
<div class="panel-body">
|
||||
|
||||
<div class="help-block">
|
||||
<?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Specify your LDAP-backend used to fetch user accounts.') ?>
|
||||
<?= Yii::t(
|
||||
'AdminModule.views_setting_authentication_ldap',
|
||||
'Specify your LDAP-backend used to fetch user accounts.'
|
||||
) ?>
|
||||
</div>
|
||||
<br>
|
||||
<?php if ($enabled): ?>
|
||||
<?php if ($errorMessage != ""): ?>
|
||||
<div class="alert alert-danger"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Status: Error! (Message: {message})', ['{message}' => $errorMessage]); ?></div>
|
||||
<?php if (!empty($errorMessage)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?= Yii::t(
|
||||
'AdminModule.views_setting_authentication_ldap',
|
||||
'Status: Error! (Message: {message})',
|
||||
['{message}' => $errorMessage]
|
||||
) ?>
|
||||
</div>
|
||||
<?php elseif ($userCount == 0): ?>
|
||||
<div class="alert alert-warning"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Status: Warning! (No users found using the ldap user filter!)'); ?></div>
|
||||
<div class="alert alert-warning">
|
||||
<?= Yii::t(
|
||||
'AdminModule.views_setting_authentication_ldap',
|
||||
'Status: Warning! (No users found using the ldap user filter!)'
|
||||
) ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-success"><?= Yii::t('AdminModule.views_setting_authentication_ldap', 'Status: OK! ({userCount} Users)', ['{userCount}' => $userCount]); ?></div>
|
||||
<div class="alert alert-success">
|
||||
<?= Yii::t(
|
||||
'AdminModule.views_setting_authentication_ldap',
|
||||
'Status: OK! ({userCount} Users)',
|
||||
['{userCount}' => $userCount]
|
||||
) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $form = ActiveForm::begin(['id' => 'authentication-settings-form']); ?>
|
||||
<?php $form = ActiveForm::begin([
|
||||
'id' => 'authentication-settings-form',
|
||||
'fieldConfig' => function ($model, $attribute) {
|
||||
return [
|
||||
'inputOptions' => [
|
||||
'class' => 'form-control',
|
||||
'readonly' => Setting::IsFixed('auth.ldap.' . $attribute, 'user')
|
||||
],
|
||||
];
|
||||
}
|
||||
]) ?>
|
||||
|
||||
<?= $form->field($model, 'enabled')->checkbox(['readonly' => Setting::IsFixed('auth.ldap.enabled', 'user')]); ?>
|
||||
<?= $form->field($model, 'enabled')->checkbox() ?>
|
||||
<hr>
|
||||
|
||||
<?= $form->field($model, 'hostname')->textInput(['readonly' => Setting::IsFixed('auth.ldap.hostname', 'user')]); ?>
|
||||
<?= $form->field($model, 'port')->textInput(['readonly' => Setting::IsFixed('auth.ldap.port', 'user')]); ?>
|
||||
<?= $form->field($model, 'encryption')->dropDownList($model->encryptionTypes, ['readonly' => Setting::IsFixed('auth.ldap.encryption', 'user')]); ?>
|
||||
<?= $form->field($model, 'username')->textInput(['readonly' => Setting::IsFixed('auth.ldap.username', 'user')]); ?>
|
||||
<?= $form->field($model, 'password')->passwordInput(['readonly' => Setting::IsFixed('auth.ldap.password', 'user')]); ?>
|
||||
<?= $form->field($model, 'baseDn')->textInput(['readonly' => Setting::IsFixed('auth.ldap.baseDn', 'user')]); ?>
|
||||
<?= $form->field($model, 'loginFilter')->textArea(['readonly' => Setting::IsFixed('auth.ldap.loginFilter', 'user')]); ?>
|
||||
<?= $form->field($model, 'userFilter')->textArea(['readonly' => Setting::IsFixed('auth.ldap.userFilter', 'user')]); ?>
|
||||
<?= $form->field($model, 'usernameAttribute')->textInput(['readonly' => Setting::IsFixed('auth.ldap.usernameAttribute', 'user')]); ?>
|
||||
<?= $form->field($model, 'emailAttribute')->textInput(['readonly' => Setting::IsFixed('auth.ldap.emailAttribute', 'user')]); ?>
|
||||
<?= $form->field($model, 'idAttribute')->textInput(['readonly' => Setting::IsFixed('auth.ldap.idAttribute', 'user')]); ?>
|
||||
<?= $form->field($model, 'refreshUsers')->checkbox(['readonly' => Setting::IsFixed('auth.ldap.refreshUsers', 'user')]); ?>
|
||||
|
||||
<?= $form->field($model, 'hostname')->textInput() ?>
|
||||
<?= $form->field($model, 'port')->textInput() ?>
|
||||
<?= $form->field($model, 'encryption')->dropDownList($model->encryptionTypes) ?>
|
||||
<?= $form->field($model, 'username')->textInput() ?>
|
||||
<?= $form->field($model, 'password')->passwordInput() ?>
|
||||
<?= $form->field($model, 'baseDn')->textInput() ?>
|
||||
<?= $form->field($model, 'loginFilter')->textArea() ?>
|
||||
<?= $form->field($model, 'userFilter')->textArea() ?>
|
||||
<?= $form->field($model, 'usernameAttribute')->textInput() ?>
|
||||
<?= $form->field($model, 'emailAttribute')->textInput() ?>
|
||||
<?= $form->field($model, 'idAttribute')->textInput() ?>
|
||||
<?= $form->field($model, 'refreshUsers')->checkbox() ?>
|
||||
<hr>
|
||||
<?= Html::submitButton(Yii::t('AdminModule.views_setting_authentication_ldap', 'Save'), ['class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>
|
||||
|
||||
<?= \humhub\widgets\DataSaved::widget(); ?>
|
||||
<?php ActiveForm::end(); ?>
|
||||
<?= Html::submitButton(
|
||||
Yii::t('AdminModule.views_setting_authentication_ldap', 'Save'),
|
||||
['class' => 'btn btn-primary', 'data-ui-loader' => '']
|
||||
) ?>
|
||||
|
||||
<?= DataSaved::widget() ?>
|
||||
<?php ActiveForm::end() ?>
|
||||
</div>
|
||||
<?php $this->endContent(); ?>
|
||||
<?php $this->endContent() ?>
|
Loading…
x
Reference in New Issue
Block a user