How to create Module based Login

You are viewing revision #2 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.

« previous (#1)

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