1
我在yii2中有2个模块,我希望允许用户使用不同的IdentityClass模块登录到这些模块。yii2 separete模块验证
问题是,当用户登录到模块A时,他自动登录模块B!这是一个配置问题?我猜测用户组件将需要为每个模块进行配置,但我不确定。
任何帮助表示赞赏。
我在yii2中有2个模块,我希望允许用户使用不同的IdentityClass模块登录到这些模块。yii2 separete模块验证
问题是,当用户登录到模块A时,他自动登录模块B!这是一个配置问题?我猜测用户组件将需要为每个模块进行配置,但我不确定。
任何帮助表示赞赏。
在模块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
}
}
我使用的模块配置一个单独的用户组成部分,但仍是用户的登录到其他模块也出现 – Andreas