2015-09-27 58 views
1

我在yii2中有2個模塊,我希望允許用戶使用不同的IdentityClass模塊登錄到這些模塊。yii2 separete模塊驗證

問題是,當用戶登錄到模塊A時,他自動登錄模塊B!這是一個配置問題?我猜測用戶組件將需要爲每個模塊進行配置,但我不確定。

任何幫助表示讚賞。

回答

0

在模塊init上拋出異常(或創建用戶重定向到登錄頁面)。

class Module extends \yii\base\Module 
{ 
    public function init() 
    { 
     parent::init(); 

     if(Yii::$app->userForSecondModule->isGuest) { 
      throw new NotFoundHttpException('Not logging in'); 
     } 

     // custom initialization code goes here 
    } 
} 

也可以使用用戶從模塊設置

class Module extends \yii\base\Module 
{ 
    public function init() 
    { 
     parent::init(); 

     Yii::configure($this, require(__DIR__ . '/config/main.php')); 

     if(Yii::$app->getModule('module')->userForSecondModule->isGuest) { 
      throw new NotFoundHttpException('Not logging in'); 
     } 

     // custom initialization code goes here 
    } 
} 
+0

我使用的模塊配置一個單獨的用戶組成部分,但仍是用戶的登錄到其他模塊也出現 – Andreas