Yii2 user management module

[size="4"]User management module for Yii 2[/size]

[size="3"]Perks [/size]

  • 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

Description is here - http://www.yiiframework.com/extension/yii2-user-management/

Hi, i really want to try this extension, but im not able to install yet, please check attached pic to see my problem:

6222

yii2 problem.jpg

My composer.json proyect file:


{

    "name": "yiisoft/yii2-app-basic",

    "description": "Yii 2 Basic Application Template",

    "keywords": ["yii2", "framework", "basic", "application template"],

    "homepage": "http://www.yiiframework.com/",

    "type": "project",

    "license": "BSD-3-Clause",

    "support": {

        "issues": "https://github.com/yiisoft/yii2/issues?state=open",

        "forum": "http://www.yiiframework.com/forum/",

        "wiki": "http://www.yiiframework.com/wiki/",

        "irc": "irc://irc.freenode.net/yii",

        "source": "https://github.com/yiisoft/yii2"

    },

    "minimum-stability": "stable",

    "require": {

        "php": ">=5.4.0",

        "yiisoft/yii2": "*",

        "yiisoft/yii2-bootstrap": "*",

        "yiisoft/yii2-swiftmailer": "*",

        "yiisoft/yii2-jui": "*"

    },

    "require-dev": {

        "yiisoft/yii2-codeception": "*",

        "yiisoft/yii2-debug": "*",

        "yiisoft/yii2-gii": "*",

        "yiisoft/yii2-faker": "*"

    },

    "config": {

        "process-timeout": 1800

    },

    "scripts": {

        "post-create-project-cmd": [

            "yii\\composer\\Installer::postCreateProject"

        ]

    },

    "extra": {

        "yii\\composer\\Installer::postCreateProject": {

            "setPermission": [

                {

                    "runtime": "0777",

                    "web/assets": "0777",

                    "yii": "0755"

                }

            ],

            "generateCookieValidationKey": [

                "config/web.php"

            ]

        },

        "asset-installer-paths": {

            "npm-asset-library": "vendor/npm",

            "bower-asset-library": "vendor/bower"

        }

    }

}



Try this code in your composer.json:


"minimum-stability": "dev",

"prefer-stable" : true,

I have created a new project with this module but when i try to login using superadmin/superadmin the login page just refresh and nothing happen. Please help

Sorry, but more information needed. Try post following code to /vendor/webvimark/module-user-management/views/auth/login.php


<?php

echo "<pre>";

var_dump($model->errors);

echo "</pre>";

?>

it was due to user component configuration from config files from the existing yii installation after removing it works fine.

Great Extension

Thanks …

Hi,

not sure if this problem affect just the webvimark’s module or not because my lack of experience on Yii, but it happens that when I add the config lines in config/web.php and config/console.php then run the migration command, nothing happens.

I just get a “No new migrations found. Your system is up-to-date”,in fact during the extension installation there aren’t any table added in the DB.

I followed these steps till number "3": https://github.com/webvimark/user-management

Do you have fresh yii2 installation ? If not, then could you please post your "web" and "console" config files (just delete all sensetive data like DB passwords before posting)

Thank you for your reply Webvimark.

It’s a fresh new installation. I just tried some things by guide 2.0 but it was just the adding of a couple of controllers and views.

This is my web.php:




<?php


$params = require(__DIR__ . '/params.php');


$config = [

    'id' => 'basic',

    'basePath' => dirname(__DIR__),

    'bootstrap' => ['log'],

    'components' => [

        'request' => [

            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation

            'cookieValidationKey' => 'ReNCzixX4Ad59J7D1veek2hcG89CgTNd',

        ],

        'cache' => [

            'class' => 'yii\caching\FileCache',

        ],

		'user' => [

          'identityClass' => 'app\models\User',

          'enableAutoLogin' => true,

        ],

		

		//User-management added by lup0z

		'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);

            }

    ],

        'errorHandler' => [

            'errorAction' => 'site/error',

        ],

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

            // send all mails to a file by default. You have to set

            // 'useFileTransport' to false and configure a transport

            // for the mailer to send real emails.

            'useFileTransport' => true,

        ],

        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],

        'db' => require(__DIR__ . '/db.php'),

    ],

    'params' => $params,


	'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';

                };

            },

    	],

	],

];


if (YII_ENV_DEV) {

    // configuration adjustments for 'dev' environment

    $config['bootstrap'][] = 'debug';

    $config['modules']['debug'] = 'yii\debug\Module';


    $config['bootstrap'][] = 'gii';

    $config['modules']['gii'] = 'yii\gii\Module';

}


return $config;



And the console.php:




<?php


Yii::setAlias('@tests', dirname(__DIR__) . '/tests');


$params = require(__DIR__ . '/params.php');

$db = require(__DIR__ . '/db.php');


return [

    'id' => 'basic-console',

    'basePath' => dirname(__DIR__),

    'bootstrap' => ['log', 'gii'],

    'controllerNamespace' => 'app\commands',

    'modules' => [

        'gii' => 'yii\gii\Module',

		'user-management' => [

        	'class' => 'webvimark\modules\UserManagement\UserManagementModule',

    	],

    ],

    'components' => [

        'cache' => [

            'class' => 'yii\caching\FileCache',

        ],

        'log' => [

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],

        'db' => $db,

    ],

    'params' => $params,

	

];




I think it’s because you have 2 user components.




    'user' => [

          'identityClass' => 'app\models\User',

          'enableAutoLogin' => true,

        ],

                

    //User-management added by lup0z

    '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);

            }

    ],



You have to replace the old one with the new component

I’ll change documentation to make this step more clear :)

Thank you for your reply Webvimark!

Just tried it: I commented the other user module but nothing changes.

Hi, lup0z. Sorry for the late answer, but I couldn’t replicate your problem, so I added mysql schema file to migrations folder.

If you can’t run migrations just export this schema to your database

Thank you so much Webvimark!

I’m doing again every step and when running “composer update”, I’ve found this out:

"Your requirements could not be resolved to an installable set of packages.

Problem 1

  • The request package webvimark/module-user-management could not be found in any version, there may be a typo in the package name.

Potential causes:

  • A typo in the package name

  • The package is not available in a stable-enough version according to your minimum-stability setting

see <https://groups.google.com/forum/#!topic/composer-dev/_g3ASeIFlrc/discussion>"

so something could change about my migration problem because of this issue?

The Pendalf posted how to solve this problem few comments above.

Try this code in your composer.json:

"minimum-stability": "dev",

"prefer-stable" : true,

Ah thank you.

I didn’t notice.

Sorry for the re-post of the problem

Ok, I just want to make you know that I succeed on downloading through your repository and when I run the migrate command, now I get this:


C:\xampp\htdocs\yiiframework\user-manager>php yii migrate --migrationPath=vendor/webvimark/module-user-management/migrations

Yii Migration Tool (based on Yii v2.0.3)


Total 10 new migrations to be applied:

        m140608_173539_create_user_table

        m140611_133903_init_rbac

        m140808_073114_create_auth_item_group_table

        m140809_072112_insert_superadmin_to_user

        m140809_073114_insert_common_permisison_to_auth_item

        m141023_141535_create_user_visit_log

        m141116_115804_add_bind_to_ip_and_registration_ip_to_user

        m141121_194858_split_browser_and_os_column

        m141201_220516_add_email_and_email_confirmed_to_user

        m141207_001649_create_basic_user_permissions


Apply the above migrations? (yes|no) [no]:yes

*** applying m140608_173539_create_user_table

Exception: Class webvimark\modules\UserManagement\UserManagementModule does not exist (C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\di\Container.php:415)

#0 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\di\Container.php(415): ReflectionClass->__construct('webvimark\modul...')

#1 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\di\Container.php(358): yii\di\Container->getDependencies('webvimark\modul..

.')

#2 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\di\Container.php(151): yii\di\Container->build('webvimark\modul...', Array,

 Array)

#3 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('webvimark\modul...', Array, Array)


#4 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\base\Module.php(354): yii\BaseYii::createObject(Array, Array)

#5 C:\xampp\htdocs\yiiframework\user-manager\vendor\webvimark\module-user-management\migrations\m140608_173539_create_user_table.php(16): yi

i\base\Module->getModule('user-management')

#6 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\db\Migration.php(81): m140608_173539_create_user_table->safeUp()

#7 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(492): yii\db\Migration->up()

#8 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(129): yii\console\controllers

\BaseMigrateController->migrateUp('m140608_173539_...')

#9 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)

#10 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)

#11 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\base\Controller.php(151): yii\base\InlineAction->runWithParams(Array)

#12 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\console\Controller.php(91): yii\base\Controller->runAction('', Array)

#13 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\base\Module.php(455): yii\console\Controller->runAction('', Array)

#14 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\console\Application.php(161): yii\base\Module->runAction('migrate', Array)


#15 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\console\Application.php(137): yii\console\Application->runAction('migrate'

, Array)

#16 C:\xampp\htdocs\yiiframework\user-manager\vendor\yiisoft\yii2\base\Application.php(375): yii\console\Application->handleRequest(Object(y

ii\console\Request))

#17 C:\xampp\htdocs\yiiframework\user-manager\yii(23): yii\base\Application->run()

#18 {main}

*** failed to apply m140608_173539_create_user_table (time: 0.019s)




Migration failed. The rest of the migrations are canceled.

Hey, as I can see you downloaded it directly instead of using composer (so I guess you’ll have problems with class autoload). For current problem you may use mysql.schema.sql in migrations/ folder.

If you’ll have futher troubles I’ll just create archive with whole project when I’ll be back from vacation and give you =)

No no, I downloaded it through "composer update".

Thank you for your support!

How can I set this behaviors for every controller (for the hole site ). It redirects to login page only when i rite this in controller//


public function behaviors()

{

    return [

        'ghost-access'=> [

            'class' => 'webvimark\modules\UserManagement\components\GhostAccessControl',

        ],

    ];

}