Difference between #4 and #3 of Module based login

unchanged
Title
Module based login
unchanged
Category
Tutorials
changed
Tags
module login authenticationauthentication, module
unchanged
Content
If you want to add _module based login_ to a site without using RBAC,  please
follow these guidelines.

Consider the situation where we want to add 3 types of login in a site:
customer, dealer, and admin.

Start by generating three modules using gii. (To do this, please refer to this
guide for module generation
[http://yiiframework.com/doc/guide/1.1/en/basics.module#creating-module](http://yiiframework.com/doc/guide/1.1/en/basics.module#creating-module
"Creating Modules"))

**Step 1**

Copy the _UserIdentity_ component to the module/components folder for each
module. We will validate each module against its table. For example, customer
validation is done using customer table, and admin validation against the admin
table

For each module, change its _UserIdentity_ authenticate() function to perform
the appropriate validation.

**Step 2**

For each module, add the following line to its main page. For example, for the
Customer module, add to Customer/CustomerModule.php  Add the following line to
init():

~~~
[php]
$this->setComponents(array(
            'errorHandler' => array(
                'errorAction' =>
'customer/default/error'),
            'user' => array(
                'class' => 'CWebUser',             
                'loginUrl' =>
Yii::app()->createUrl('customer/default/login'),
            )
        ));

Yii::app()->user->setStateKeyPrefix('_customer');
~~~

**Step 3**

Create the login/logout action in each module's _DefaultController_. 

For example, for the Customer module:

Create the actionLogin() in Customer/controllers/DefaultController.php.

Also, create actionLogout() as follows:

~~~
[php]
public function actionLogout() {
        Yii::app()->user->logout(false);
       
$this->redirect(Yii::app()->getModule('admin')->user->loginUrl);
    }


~~~

Thanks to ricardograna for sharing some configurations