2024-03-22 14:48:35 +08:00
|
|
|
<?php
|
|
|
|
|
2024-03-25 15:38:47 +08:00
|
|
|
use app\assets\FontAwesomeAsset;
|
|
|
|
use app\models\PublicKeyCredentialSourceRepository;
|
2024-03-26 14:26:59 +08:00
|
|
|
use app\models\User;
|
2024-03-25 15:38:47 +08:00
|
|
|
use app\utils\FileSizeHelper;
|
|
|
|
use app\utils\IPLocation;
|
|
|
|
use kartik\editable\Editable;
|
2024-03-26 14:26:59 +08:00
|
|
|
use yii\bootstrap5\ActiveForm;
|
|
|
|
use yii\bootstrap5\Modal;
|
2024-03-22 14:48:35 +08:00
|
|
|
use yii\helpers\Html;
|
|
|
|
use yii\web\YiiAsset;
|
|
|
|
use yii\widgets\DetailView;
|
|
|
|
|
|
|
|
/** @var yii\web\View $this */
|
|
|
|
/** @var app\models\User $model */
|
|
|
|
|
2024-03-25 15:38:47 +08:00
|
|
|
$this->title = '用户ID: ' . $model->id;
|
2024-03-23 14:28:36 +08:00
|
|
|
$this->params['breadcrumbs'][] = ['label' => '用户管理', 'url' => ['user']];
|
2024-03-22 14:48:35 +08:00
|
|
|
$this->params['breadcrumbs'][] = $this->title;
|
2024-03-23 14:28:36 +08:00
|
|
|
$alreadyDisabled = $model->status == 0;
|
2024-03-25 15:38:47 +08:00
|
|
|
$IPLocation = new IPLocation();
|
2024-03-22 14:48:35 +08:00
|
|
|
YiiAsset::register($this);
|
2024-03-25 15:38:47 +08:00
|
|
|
FontAwesomeAsset::register($this);
|
2024-03-27 14:14:55 +08:00
|
|
|
$this->registerCssFile('@web/css/admin-userv.css');
|
2024-03-22 14:48:35 +08:00
|
|
|
?>
|
|
|
|
<div class="user-view">
|
|
|
|
|
2024-03-23 14:28:36 +08:00
|
|
|
<h1>用户详情</h1>
|
2024-03-22 14:48:35 +08:00
|
|
|
|
|
|
|
<p>
|
2024-03-25 16:48:34 +08:00
|
|
|
<?= Html::a('禁用二步验证', ['user-totpoff', 'id' => $model->id], [
|
2024-03-26 14:26:59 +08:00
|
|
|
'class' => 'btn btn-danger' . ($model->is_otp_enabled == 0 ? ' disabled' : ''),
|
2024-03-22 14:48:35 +08:00
|
|
|
'data' => [
|
2024-03-25 16:48:34 +08:00
|
|
|
'confirm' => '你确定要取消这个用户的多因素登录吗?',
|
2024-03-22 14:48:35 +08:00
|
|
|
'method' => 'post',
|
|
|
|
],
|
2024-03-25 16:48:34 +08:00
|
|
|
'title' => '点击取消用户的多因素登录',
|
2024-03-22 14:48:35 +08:00
|
|
|
]) ?>
|
2024-03-26 14:26:59 +08:00
|
|
|
<?= Html::button('重置密码', [
|
|
|
|
'class' => 'btn btn-danger',
|
|
|
|
'data-bs-toggle' => 'modal',
|
|
|
|
'data-bs-target' => '#resetPasswordModal',
|
|
|
|
'title' => '点击重置用户密码',
|
|
|
|
]) ?>
|
2024-03-22 14:48:35 +08:00
|
|
|
</p>
|
|
|
|
|
2024-03-25 16:48:34 +08:00
|
|
|
|
2024-03-22 14:48:35 +08:00
|
|
|
<?= DetailView::widget([
|
|
|
|
'model' => $model,
|
|
|
|
'attributes' => [
|
2024-03-25 15:38:47 +08:00
|
|
|
['attribute' => 'id', 'label' => '用户ID'],
|
|
|
|
['attribute' => 'username', 'label' => '用户名'],
|
|
|
|
['attribute' => 'name', 'label' => '昵称', 'format' => 'raw', 'value' => function ($model) {
|
|
|
|
return Editable::widget([
|
|
|
|
'name' => 'name',
|
2024-03-27 14:14:55 +08:00
|
|
|
'asPopover' => true,
|
2024-03-25 15:38:47 +08:00
|
|
|
'value' => $model->name,
|
|
|
|
'header' => '昵称',
|
|
|
|
'size' => 'md',
|
|
|
|
'options' => ['class' => 'form-control', 'placeholder' => '在这里输入新的昵称...'],
|
|
|
|
]);
|
|
|
|
}],
|
|
|
|
['attribute' => 'email', 'label' => '电子邮件'],
|
|
|
|
['label' => '头像', 'format' => 'html', 'value' => function ($model) {
|
|
|
|
return $model->getGravatar(email: $model->email, s: 100, img: true);
|
|
|
|
}],
|
|
|
|
['attribute' => 'status', 'label' => '账户状态', 'format' => 'raw', 'value' => function ($model) {
|
2024-03-26 14:26:59 +08:00
|
|
|
if (Yii::$app->user->id == $model->id) {
|
2024-03-25 16:48:34 +08:00
|
|
|
return $model->status == 0 ? '禁用' : '启用';
|
|
|
|
}
|
2024-03-25 15:38:47 +08:00
|
|
|
return Editable::widget([
|
|
|
|
'name' => 'status',
|
2024-03-25 16:48:34 +08:00
|
|
|
'value' => $model->status == 0 ? '禁用' : '启用',
|
2024-03-25 15:38:47 +08:00
|
|
|
'asPopover' => true,
|
|
|
|
'header' => '账户状态',
|
|
|
|
'format' => Editable::FORMAT_BUTTON,
|
|
|
|
'inputType' => Editable::INPUT_DROPDOWN_LIST,
|
2024-03-25 16:48:34 +08:00
|
|
|
'data' => [0 => '禁用',
|
|
|
|
1 => '启用',],
|
2024-03-25 15:38:47 +08:00
|
|
|
'options' => ['class' => 'form-control'],
|
|
|
|
]);
|
|
|
|
}],
|
|
|
|
['attribute' => 'created_at', 'label' => '创建时间', 'value' => function ($model) {
|
|
|
|
// 日期时间 (xx天前)
|
2024-04-04 15:37:48 +08:00
|
|
|
return $model->created_at . ' (' . Yii::$app->formatter->asRelativeTime(new DateTime($model->created_at, new DateTimeZone('GMT+8'))) . ')';
|
2024-03-25 15:38:47 +08:00
|
|
|
}],
|
|
|
|
['attribute' => 'last_login', 'label' => '最后登录时间', 'value' => function ($model) {
|
|
|
|
// 日期时间 (xx天前)
|
2024-04-04 15:37:48 +08:00
|
|
|
return $model->last_login . ' (' . Yii::$app->formatter->asRelativeTime(new DateTime($model->last_login, new DateTimeZone('GMT+8'))) . ')';
|
2024-03-25 15:38:47 +08:00
|
|
|
}],
|
|
|
|
['attribute' => 'last_login_ip', 'label' => '上次登录IP', 'value' => function ($model) use ($IPLocation) {
|
|
|
|
if (Yii::$app->params['enableIpInfo']) {
|
|
|
|
return $IPLocation->getFormatDetails($model->last_login_ip);
|
|
|
|
} else {
|
|
|
|
return $model->last_login_ip;
|
|
|
|
}
|
|
|
|
}],
|
2024-03-26 14:26:59 +08:00
|
|
|
['attribute' => 'bio', 'label' => '用户简介', 'format' => 'raw', 'value' => function ($model) {
|
2024-03-25 16:48:34 +08:00
|
|
|
return Editable::widget([
|
2024-03-26 14:26:59 +08:00
|
|
|
'name' => 'bio',
|
2024-03-25 16:48:34 +08:00
|
|
|
'asPopover' => true,
|
|
|
|
'displayValue' => '查看',
|
|
|
|
'inputType' => Editable::INPUT_TEXTAREA,
|
|
|
|
'value' => $model->bio,
|
|
|
|
'header' => '用户简介',
|
|
|
|
'submitOnEnter' => false,
|
2024-03-26 14:26:59 +08:00
|
|
|
'size' => 'lg',
|
|
|
|
'options' => ['class' => 'form-control', 'rows' => 5]
|
2024-03-25 16:48:34 +08:00
|
|
|
]);
|
|
|
|
}],
|
2024-03-25 15:38:47 +08:00
|
|
|
['attribute' => 'role', 'label' => '用户身份', 'value' => function ($model) {
|
|
|
|
return $model->role == 'user' ? '用户' : '管理员';
|
|
|
|
}],
|
|
|
|
['attribute' => 'is_otp_enabled', 'label' => '多因素登录', 'value' => function ($model) {
|
|
|
|
return $model->is_otp_enabled == 0 ? '禁用' : '启用';
|
|
|
|
}],
|
|
|
|
['label' => 'Passkey', 'value' => function ($Model) {
|
|
|
|
$PKCSR = new PublicKeyCredentialSourceRepository();
|
|
|
|
$UserEntitys = $PKCSR->findAllForUserEntity($Model);
|
|
|
|
if (empty($UserEntitys)) {
|
|
|
|
return '禁用';
|
|
|
|
} else {
|
|
|
|
return '启用';
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
['label' => '保险箱状态', 'value' => function ($model) {
|
|
|
|
if ($model->role == 'admin') {
|
|
|
|
return '不可用';
|
|
|
|
}
|
|
|
|
return empty($model->vault_secret) ? '未初始化' : '已启用';
|
|
|
|
}],
|
|
|
|
['label' => '网盘已用空间', 'value' => function ($model) {
|
|
|
|
if ($model->role == 'admin') {
|
|
|
|
return '不可用';
|
|
|
|
}
|
|
|
|
return FileSizeHelper::formatBytes(FileSizeHelper::getUserHomeDirSize($model->id));
|
|
|
|
}],
|
|
|
|
['label' => '保险箱已用空间', 'value' => function ($model) {
|
|
|
|
if ($model->role == 'admin') {
|
|
|
|
return '不可用';
|
|
|
|
}
|
|
|
|
return FileSizeHelper::formatBytes(FileSizeHelper::getUserVaultDirSize($model->id));
|
|
|
|
}],
|
2024-03-27 14:14:55 +08:00
|
|
|
// ['attribute' => 'storage_limit', 'label' => '存储容量限制', 'value' => function ($model) {
|
|
|
|
// if ($model->role == 'admin') {
|
|
|
|
// return '不可用';
|
|
|
|
// }
|
|
|
|
// return FileSizeHelper::formatMegaBytes($model->storage_limit);
|
|
|
|
// }],
|
|
|
|
['attribute' => 'storage_limit', 'label' => '存储容量限制', 'format' => 'raw', 'value' => function ($model) {
|
2024-03-25 15:38:47 +08:00
|
|
|
if ($model->role == 'admin') {
|
|
|
|
return '不可用';
|
|
|
|
}
|
2024-03-27 14:14:55 +08:00
|
|
|
return Editable::widget([
|
|
|
|
'name' => 'storage_limit',
|
|
|
|
'asPopover' => true,
|
|
|
|
'value' => FileSizeHelper::formatMegaBytes($model->storage_limit),
|
|
|
|
'header' => '存储容量限制(最小1MB)',
|
|
|
|
'size' => 'md',
|
|
|
|
'options' => ['class' => 'form-control', 'placeholder' => '在这里输入容量限制(最小值为1MB)...'],
|
|
|
|
]);
|
2024-03-25 15:38:47 +08:00
|
|
|
}],
|
|
|
|
['attribute' => 'storage_limit', 'format' => 'html', 'label' => '存储空间使用状态', 'value' => function ($model) {
|
|
|
|
if ($model->role == 'admin') {
|
|
|
|
return '不可用';
|
|
|
|
}
|
|
|
|
return FileSizeHelper::getUsedPercent($model->id) . '<br>' . FileSizeHelper::getFormatUserAllDirSize($model->id) . ' / ' . FileSizeHelper::formatMegaBytes($model->storage_limit);
|
|
|
|
}],
|
2024-03-22 14:48:35 +08:00
|
|
|
],
|
2024-03-26 14:26:59 +08:00
|
|
|
])
|
|
|
|
?>
|
2024-03-22 14:48:35 +08:00
|
|
|
</div>
|
2024-03-26 14:26:59 +08:00
|
|
|
|
|
|
|
<?php
|
|
|
|
Modal::begin([
|
|
|
|
'title' => '<h4>重置密码</h4>',
|
|
|
|
'id' => 'resetPasswordModal',
|
|
|
|
'size' => 'modal-lg',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$form = ActiveForm::begin(['id' => 'reset-password-form', 'action' => ['admin/user-pwdreset'], 'method' => 'post']);
|
|
|
|
|
|
|
|
echo $form->field($model, 'id')->hiddenInput()->label(false);
|
|
|
|
echo $form->field($model, 'password')->passwordInput(['maxlength' => true, 'value' => ''])->label('新密码');
|
|
|
|
|
|
|
|
echo Html::submitButton('提交', ['class' => 'btn btn-primary']);
|
|
|
|
|
|
|
|
ActiveForm::end();
|
|
|
|
Modal::end();
|
|
|
|
?>
|