Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ldap support #168

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,33 @@ Perks
* Visit log
* Optimised (zero DB queries during usual user workflow)
* Nice widgets like GhostMenu or GhostHtml::a where elements are visible only if user has access to route where they point
* LDAP support

Features of this fork
~~~

* Correct maximum length of an email address
* Improved Spanish translation


Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

Add the following lines to your `composer.json` file:
```
composer require webvimark/module-user-management
```

or add

```
"webvimark/module-user-management": "^1"
"repositories": [
{
"type": "vcs",
"url": "https://github.com/quique/user-management"
}
],
"require": {
"webvimark/module-user-management": "dev-dev",
},
```

to the require section of your `composer.json` file.

Configuration
---

Expand All @@ -40,6 +46,8 @@ Configuration

'components'=>[
'user' => [
// 'identityClass' => 'app\models\User',
'enableLdap' => false, // Change it to true to enable LDAP authentication
'class' => 'webvimark\modules\UserManagement\components\UserConfig',

// Comment this if you don't want to record user logins
Expand All @@ -65,7 +73,7 @@ Configuration
// $: anchored to the end of the string

//'passwordRegexp' => '^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$',


// Here you can set your handler to change layout for any controller or action
// Tip: you can use this event in any module
Expand All @@ -80,6 +88,22 @@ Configuration

```

If needed, you can extend the base User class in app/models/User.php
(change the identityClass in the configuration accordingly):
```php
<?php
namespace app\models;

use webvimark\modules\UserManagement\models\User as BaseUser;
// use Yii;
// use yii\web\ServerErrorHttpException;

class User extends BaseUser
{
// Your custom stuff (vg your own getUserAttributes() function)
}
```

To learn about events check:

* http://www.yiiframework.com/doc-2.0/guide-concept-events.html
Expand Down Expand Up @@ -126,6 +150,15 @@ public function behaviors()

```

5) If you want to use LDAP authentication, add these lines to your params:
```php
'ldap' => [
'host' => 'ldapserver.domain.net',
'port' => 389,
'base_dn' => 'ou=unit, dc=domain, dc=net', // Base Distinguished Name
],
```

Where you can go
-----

Expand Down
101 changes: 52 additions & 49 deletions components/UserConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,60 @@
use Yii;

/**
* Class UserConfig
* @package webvimark\modules\UserManagement\components
* Class UserConfig.
*/
class UserConfig extends User
{
/**
* @inheritdoc
*/
public $identityClass = 'webvimark\modules\UserManagement\models\User';

/**
* @inheritdoc
*/
public $enableAutoLogin = true;

/**
* @inheritdoc
*/
public $cookieLifetime = 2592000;

/**
* @inheritdoc
*/
public $loginUrl = ['/user-management/auth/login'];

/**
* Allows to call Yii::$app->user->isSuperadmin
*
* @return bool
*/
public function getIsSuperadmin()
{
return @Yii::$app->user->identity->superadmin == 1;
}

/**
* @return string
*/
public function getUsername()
{
return @Yii::$app->user->identity->username;
}

/**
* @inheritdoc
*/
protected function afterLogin($identity, $cookieBased, $duration)
{
AuthHelper::updatePermissions($identity);

parent::afterLogin($identity, $cookieBased, $duration);
}
/**
* {@inheritdoc}
*/
public $identityClass = 'webvimark\modules\UserManagement\models\User';

/**
* {@inheritdoc}
*/
public $enableAutoLogin = true;

/**
* {@inheritdoc}
*/
public $enableLdap = false;

/**
* {@inheritdoc}
*/
public $cookieLifetime = 2592000;

/**
* {@inheritdoc}
*/
public $loginUrl = ['/user-management/auth/login'];

/**
* Allows to call Yii::$app->user->isSuperadmin.
*
* @return bool
*/
public function getIsSuperadmin()
{
return @Yii::$app->user->identity->superadmin == 1;
}

/**
* @return string
*/
public function getUsername()
{
return @Yii::$app->user->identity->username;
}

/**
* {@inheritdoc}
*/
protected function afterLogin($identity, $cookieBased, $duration)
{
AuthHelper::updatePermissions($identity);

parent::afterLogin($identity, $cookieBased, $duration);
}
}
Loading