如何解决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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。