1

I have admin module and different CWebUser(adminuser) for that module. It works good for login. So I can login in main app and in module by different users. But when I call logout method in module

Yii::app()->getModule('admin')->adminuser->logout();

it log me out from module and from main app as well.
how can I fix it?
thanks beforehand.

Anton G
  • 129
  • 1
  • 12
  • 1
    Logout by default will remove the entire session from the user (see http://www.yiiframework.com/doc/api/1.1/CWebUser#logout-detail). – Ian Hunter Dec 15 '12 at 20:09
  • Thanks. That helped Yii::app()->getModule('admin')->adminuser->logout(false); – Anton G Dec 15 '12 at 20:44

1 Answers1

1

I think the key is stateKeyPrefix which can be used to tell different modules to use different session keys. I will put main config file user section.

'user' => [
     'allowAutoLogin' => true,
     **'stateKeyPrefix' => 'YOUR-DEFAULT_',**
     'loginUrl' => array('/login'),
     'class' => 'application.wsi.auth.WSIWebUser',
     'authTimeout' => 3600 * 24 // 1 hour
],

I have Admin module and I will put my AdminModule.php for you.

class AdminModule extends \CWebModule 
{   
      public $defaultController = 'index';

      public function init()
      {
          $this->setImport(array(
             'admin.components.*',
          ));
          $this->layout = 'main';
          \Yii::app()->setComponents(array(
              'authManager' => array(
                   'class' => 'CPhpAuthManager',
                   'authFile' => \Yii::getPathOfAlias('admin.data.auth') .'php',
                   'showErrors' => true,
              ),
              'user' => array(
                   'stateKeyPrefix' => 'admin_',
                   'loginUrl' => \Yii::app()->createUrl('/admin/index/login'),
                   'class' => 'AdminWebUser',
                   'authTimeout' => 3600 * 24 // 1 day
              ),
          ), false);

      }

}

I have components folder in admin module with AdminWebUser class in it as well.

class AdminWebUser extends \CWebUser {

    public function getId() {
        return Yii::app ()->user->getState ( 'id' );
    }
    public function getName() {
        return Yii::app ()->user->getState ( 'name' );
    }

    public function getRole() {
        return Yii::app ()->user->getState ( 'role' );
    }

    public function getEmail() {
        return Yii::app ()->user->getState ( 'email' );
    }
}

The rest of login and logout controller codes are same. Hope it helps. If not please let me know.

Mohamad Eghlima
  • 970
  • 10
  • 23