From ae1ed4e1a070ae3ce4797147adafa8ad6f649355 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sun, 3 Mar 2024 14:25:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=98=B5=E7=A7=B0=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=20(=E9=BB=98=E8=AE=A4=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E5=92=8C=E7=94=A8=E6=88=B7=E5=90=8D=E7=9B=B8=E5=90=8C)=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=BC=96=E8=BE=91=E4=B8=AA=E4=BA=BA=E7=AE=80?= =?UTF-8?q?=E4=BB=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/UserController.php | 8 +++++++- models/User.php | 4 +++- views/user/info.php | 20 +++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/controllers/UserController.php b/controllers/UserController.php index 150a2a7..4fc9e0e 100644 --- a/controllers/UserController.php +++ b/controllers/UserController.php @@ -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 diff --git a/models/User.php b/models/User.php index 817db76..2a8065a 100644 --- a/models/User.php +++ b/models/User.php @@ -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', diff --git a/views/user/info.php b/views/user/info.php index fdec04b..bd83c76 100644 --- a/views/user/info.php +++ b/views/user/info.php @@ -114,16 +114,17 @@ $totalUsedPercent = min(($usedPercent + $vaultUsedPercent), 100); //总已用百
网盘已用空间 - + + ', ['home/index']) ?> +
保险箱已用空间 - + + + ', ['site/index']) ?> +
@@ -142,7 +143,12 @@ $totalUsedPercent = min(($usedPercent + $vaultUsedPercent), 100); //总已用百
- + + field($model, 'bio')->textarea(['rows' => 6])->label('简介') ?> +
+ 'btn btn-success']) ?> +
+