How to create Module based Login

You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#2) »

Lets say we have 3 modules (customer, user, admin) in an application and we need, separate logins for each module.

We can achieve this by adding a prefix to the name of session variable for each module.

Lets take 'admin' module:

Inside your admin/AdminModule.php file, add the following lines to the 'init' function

Yii::app()->user->setStateKeyPrefix('_admin');

OR

Yii::app()->setComponents(array(
            'errorHandler' => array(
                'errorAction' => 'admin/default/error',
            ),
            'user' => array(
                'class' => 'CWebUser',
                'stateKeyPrefix' => '_admin',
                'loginUrl' => Yii::app()->createUrl($this->getId() . '/default/login'),
            ),
        ));