2024-03-23 14:28:03 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\utils;
|
|
|
|
|
|
|
|
use app\models\User;
|
|
|
|
use Yii;
|
2024-03-26 14:40:34 +08:00
|
|
|
use yii\base\Exception;
|
2024-03-23 14:28:03 +08:00
|
|
|
|
2024-03-26 14:40:34 +08:00
|
|
|
/**
|
|
|
|
* 管理员工具
|
|
|
|
*/
|
2024-03-23 14:28:03 +08:00
|
|
|
class AdminSword
|
|
|
|
{
|
2024-03-26 14:40:34 +08:00
|
|
|
/**
|
|
|
|
* 强制用户下线
|
|
|
|
* 通过修改用户的auth_key来实现
|
|
|
|
* @param $id
|
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2024-03-23 14:28:03 +08:00
|
|
|
public static function forceUserLogout($id):string
|
|
|
|
{
|
|
|
|
$user = User::findOne($id);
|
|
|
|
if ($user) {
|
|
|
|
$user->auth_key = Yii::$app->security->generateRandomString();
|
|
|
|
$user->save(false);
|
|
|
|
return '用户已被强制下线';
|
|
|
|
} else {
|
|
|
|
return '用户不存在';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|