Yii2如何根据用户类型注销

问题描述

我要使特定类型的用途在一定时间后退出,其他应保持登录状态直到手动退出 之前

$rules = $request->validate([
   'game_id' => 'required|exists:games,id','team1_id' => 'required|exists:teams,id|in:games,'team2_id' => 'required|exists:teams,]);

以及下面的webUser.php

 'user' => [
            'class' => app\components\WebUser::class,'identityClass' => app\modules\ecosmob\auth\models\UserMaster::class,'enableAutoLogin' => false,'loginUrl' => ['/auth/auth/login']
            ]

main.php

public function init()
    {
        parent::init();

        $authTimeout = (new Query())
            ->select('gwc_value')
            ->from('global_web_config')
            ->where('gwc_key = :gwc_key',['gwc_key' => 'session_timeout'])
            ->scalar();

        if ($authTimeout) {
            $this->authTimeout = ($authTimeout * 60) - 5;
        } else {
            $this->authTimeout = AUTH_TIMEOUT_DYNAMIC;
        }
    }

我强烈要求它恢复功能并为所有用户进行自动登录,并使用登录持续时间使某些类型的用户退出,但无法按以下方式工作

Yii::$app->view->registerMetaTag(['http-equiv' => 'refresh','content' => Yii::$app->user->authTimeout + 5]);

和登录模式下

 'user' => [
            'class' => app\components\WebUser::class,'enableAutoLogin' => true,'loginUrl' => ['/auth/auth/login'],'enableSession'=>true
        ],

解决方法

可能有不同的解决方案,但是我想到的第一个解决方案是对EVENT_BEFORE_LOGOUT事件做出反应。您可以在此处检查是否要注销用户,并让注销过程完成(或不完成)。选中yii\web\User::beforeLogout

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...