Multiple CWebUser objects

Hi,

i am trying to have two different user-objects in our application.

So i extended CWebApplication and added the CWebUser object Yii::app()->backendUser.

The problem is now, that if i use the login for backendUser, the ‘old’ Yii::app()->user object is also logged in, and vice versa.

Is there a way to do this, or can there only be one object of CWebUser in an application?

Thanks in advance,

Florian

I assume you want to have a different user object in the backend module?

Open BackendModule.php and add this to the init() method:




Yii::app()->setComponent('user', Yii::app()->backendUser);



and in your config define the backend user (you don’t need to extend CWebApplication):




'components'=> array(

   ...

   'backendUser' => array(

      'class' => 'CWebUser',

   ),

   ...

),



Now in the backend module you can simply use Yii::app()->user which refers to the configured backendUser.

Thanks for your answer.

The problem is, that i need to know in the frontend, if the user is logged-in in the backend. Moreover he can also be logged-in in the frontend, at the same time.

That’s why i try to use two objects of CWebUser. But they seem to interfere each other…

I found a solution which seems to work for us here.

We use a different stateKeyPrefix for the second user instance.




'components'=> array(

   ...

   'backendUser' => array(

      'class' => 'CWebUser',

      'stateKeyPrefix'=>'backend',

   ),

   ...

),



With this set, the two instances don’t interfere anymore.

@florianwalter:

Nice approach. Please let us know, in case you find any issues with this solution.

I tried the solution from @florianwalter but if you logout of one it will log you out of the other.

Is these another way around this?

Try logout(false);

Am a newbie

In my application i want to implement two login instances

1.Jobseeker

2.Recruiters

So far i have being able to do it but the Yii::app()->user->isGuest and Yii::app()->jobseeker->isGuest

still refer to each other. This is my configuration.

‘components’=>array(

	'user'=>array(


		// enable cookie-based authentication


		//'allowAutoLogin'=>true,


                    'loginUrl'=>array('companydetails/accessdenied'),


                    'returnUrl'=>array('companydetails/comarea'),


                    'stateKeyPrefix'=>'_com'


	),


            'jobseeker'=>array(


		// enable cookie-based authentication


		//'allowAutoLogin'=>true,


                     'class'=>'CWebUser',


                    'loginUrl'=>array('jobseeker/j_logins'),


                    'stateKeyPrefix'=>'_js',


                   // 'returnUrl'=>array('jobseeker/jsarea'),


	),

i notice something. If i add ‘stateKeyPrefix’=>’_js’,or ‘stateKeyPrefix’=>’_com’ it will b redirecting me to ‘loginUrl’=>array(‘companydetails/accessdenied’),

Please help!!! :(

[/quote]