PHPackages                             dvdkrgr/module-user-management - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. dvdkrgr/module-user-management

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

dvdkrgr/module-user-management
==============================

Improved webvimark/module-user-management (hybrid mode local database + ldap)

012PHP

Since Aug 12Pushed 10y ago1 watchersCompare

[ Source](https://github.com/dvdkrgr/user-management)[ Packagist](https://packagist.org/packages/dvdkrgr/module-user-management)[ RSS](/packages/dvdkrgr-module-user-management/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

This is not the original webvimark/module-user-management package!
------------------------------------------------------------------

[](#this-is-not-the-original-webvimarkmodule-user-management-package)

This package is modified like the following:

It is possible to set the boolean attribute ldap\_user for an user object:

```
$user->ldap_user = true
```

A user declared as an ldap user will not be authenticated to the local database, instead it will be checked against the directory.

If the the login is successful the user will be logged in as the user that is given in the local database.

You can set multiple LDAP servers and multiple LDAP domains inside the config file:

```
    'user' => [
      'class' => 'webvimark\modules\UserManagement\components\UserConfig',
      'ldapServer' => ['10.11.12.13','1.2.3.4','99.99.99.99'],
      'ldapDomain' => ['YOURDOMAIN','ANOTHERDOMAIN'],
     ]

```

The login procedure will try out every server/domain combination with the given credentials. If you want to use a server port just declare the LDAP server like `12.13.14.16:9999`

Example usage of this plugin:

You have local users inside the database with passwords (non ldap users). Additionally to this you want to bind an active directory to your application.

In this case you could create a Yii2 command controller that is going to run monthly/weekly/daily/hourly (whatever you want) and synchronizes the ldap users into yout database like the this:

```
$security = new \yii\base\Security();
$new_user = new \webvimark\modules\UserManagement\models\User;
$new_user->id = NULL;
$new_user->username = "newuser";
$new_user->password = md5($security->generateRandomString());
$new_user->email = "newuser@example.com";
$new_user->email_confirmed = true;
$new_user->ldap_user = true;
$new_user->save();
```

Notice: I'm using $security-&gt;generateRandomString inside md5() method to generate a random strong password inside the local database. It is just necessary to create this user to have an user object on the webpage that is controlled by our ldap user.

User management module for Yii 2
================================

[](#user-management-module-for-yii-2)

Perks
-----

[](#perks)

- User management
- RBAC (roles, permissions and stuff) with web interface
- Registration, authorization, password recovery and so on
- 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

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

[](#installation)

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

Either run

```
composer require --prefer-dist webvimark/module-user-management "*"

```

or add

```
"webvimark/module-user-management": "*"

```

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

Configuration
-------------

[](#configuration)

1. In your config/web.php

```
'components'=>[
	'user' => [
		'class' => 'webvimark\modules\UserManagement\components\UserConfig',

		// Comment this if you don't want to record user logins
		'on afterLogin' => function($event) {
				\webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id);
			}
	],
],

'modules'=>[
	'user-management' => [
		'class' => 'webvimark\modules\UserManagement\UserManagementModule',

		// Here you can set your handler to change layout for any controller or action
		// Tip: you can use this event in any module
		'on beforeAction'=>function(yii\base\ActionEvent $event) {
				if ( $event->action->uniqueId == 'user-management/auth/login' )
				{
					$event->action->controller->layout = 'loginLayout.php';
				};
			},
	],
],
```

To learn about events check:

-
-

Layout handler example in *AuthHelper::layoutHandler()*

To see full list of options check *UserManagementModule* file

2. In your config/console.php (this is needed for migrations and working with console)

```
'modules'=>[
	'user-management' => [
		'class' => 'webvimark\modules\UserManagement\UserManagementModule',
	],
],
```

3. Run migrations

```
./yii migrate --migrationPath=vendor/webvimark/module-user-management/migrations/
```

4. In you base controller

```
public function behaviors()
{
	return [
		'ghost-access'=> [
			'class' => 'webvimark\modules\UserManagement\components\GhostAccessControl',
		],
	];
}
```

Where you can go
----------------

[](#where-you-can-go)

```
