新增昵称字段

(默认情况下和用户名相同)
支持编辑个人简介
This commit is contained in:
Chenx221 2024-03-03 14:25:14 +08:00
parent ba2d350baf
commit ae1ed4e1a0
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
3 changed files with 23 additions and 9 deletions

View File

@ -302,6 +302,7 @@ class UserController extends Controller
$model->auth_key = Yii::$app->security->generateRandomString();
$model->created_at = date('Y-m-d H:i:s');
$model->role = 'user';
$model->name = $model->username; //用户默认昵称为用户名,后期可以修改
if ($model->save(false)) { // save without validation
Yii::$app->session->setFlash('success', 'Registration successful. You can now log in.');
return $this->redirect(['login']);
@ -334,7 +335,12 @@ class UserController extends Controller
$usedSpace = FileSizeHelper::getDirectorySize($dataDirectory);
$vaultUsedSpace = 0; // 保险箱已用空间暂时为0
$storageLimit = $model->storage_limit;
if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
if($model->save()){
Yii::$app->session->setFlash('success', '个人简介已更新');
return $this->refresh();
}
}
return $this->render('info', [
'model' => $model,
'usedSpace' => $usedSpace, // B

View File

@ -12,6 +12,7 @@ use yii\web\IdentityInterface;
*
* @property int $id 用户ID
* @property string|null $username 用户名
* @property string|null $name 昵称
* @property string|null $password 密码
* @property string|null $auth_key authkey
* @property string|null $email 邮箱
@ -57,7 +58,7 @@ class User extends ActiveRecord implements IdentityInterface
[['username', 'password'], 'required', 'on' => 'login'],
[['username', 'password', 'email', 'password2'], 'required', 'on' => 'register'],
['username', 'string', 'min' => 3, 'max' => 12],
['password', 'string', 'min' => 6, 'max' => 24],
['password', 'string', 'min' => 6, 'max' => 24, 'on' => 'register'],
['password2', 'compare', 'compareAttribute' => 'password', 'on' => 'register'],
['email', 'email', 'on' => 'register'],
['username', 'unique', 'on' => 'register'],
@ -73,6 +74,7 @@ class User extends ActiveRecord implements IdentityInterface
return [
'id' => 'ID',
'username' => 'Username',
'name' => 'Name',
'password' => 'Password',
'auth_key' => 'Auth Key',
'email' => 'Email',

View File

@ -114,16 +114,17 @@ $totalUsedPercent = min(($usedPercent + $vaultUsedPercent), 100); //总已用百
<div class="legend-item">
<span class="legend-color" style="background-color: rgb(52,131,250);"></span>
<span>网盘已用空间</span>
<span style="margin-left: auto;"><?= $usedSpace_F ?> <i
class="fa-solid fa-arrow-up-right-from-square"
style="font-size: 0.75rem;"></i></span>
<span style="margin-left: auto;"><?= $usedSpace_F ?>
<?= Html::a('<i class="fa-solid fa-arrow-up-right-from-square" style="font-size: 0.75rem;"></i>', ['home/index']) ?>
</span>
</div>
<div class="legend-item">
<span class="legend-color" style="background-color: rgb(196,134,0);"></span>
<span>保险箱已用空间</span>
<span style="margin-left: auto;"><?= $vaultUsedSpace_F ?> <i
class="fa-solid fa-arrow-up-right-from-square"
style="font-size: 0.75rem;"></i></span>
<span style="margin-left: auto;"><?= $vaultUsedSpace_F ?>
<!-- PENDING-->
<?= Html::a('<i class="fa-solid fa-arrow-up-right-from-square" style="font-size: 0.75rem;"></i>', ['site/index']) ?>
</span>
</div>
</div>
</div>
@ -142,7 +143,12 @@ $totalUsedPercent = min(($usedPercent + $vaultUsedPercent), 100); //总已用百
</h2>
<div id="collapseBio" class="accordion-collapse collapse">
<div class="accordion-body">
<!-- 修改bio相关内容 -->
<?php $form = yii\widgets\ActiveForm::begin(); ?>
<?= $form->field($model, 'bio')->textarea(['rows' => 6])->label('简介') ?>
<div class="form-group">
<?= yii\helpers\Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
</div>
<?php yii\widgets\ActiveForm::end(); ?>
</div>
</div>
</div>