yii2-netdisk/utils/AdminSword.php

32 lines
627 B
PHP
Raw Normal View History

<?php
namespace app\utils;
use app\models\User;
use Yii;
2024-03-26 14:40:34 +08:00
use yii\base\Exception;
2024-03-26 14:40:34 +08:00
/**
* 管理员工具
*/
class AdminSword
{
2024-03-26 14:40:34 +08:00
/**
* 强制用户下线
* 通过修改用户的auth_key来实现
* @param $id
* @return string
* @throws Exception
*/
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 '用户不存在';
}
}
}