From 555a65ae7933ef29acda6486f7a1a43a22578d7c Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sun, 10 Mar 2024 17:11:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E4=BF=9D=E9=99=A9?= =?UTF-8?q?=E7=AE=B1=E7=9A=84=E5=88=9D=E5=A7=8B=E5=8C=96=E5=92=8C=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E9=A1=B5=E9=9D=A2=20*=E5=8A=9F=E8=83=BD=E6=9C=AA?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/VaultController.php | 6 +++++- models/User.php | 12 ++++++++---- views/vault/_gateway.php | 28 ++++++++++++++++++++++++++++ views/vault/_init.php | 28 ++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 views/vault/_gateway.php create mode 100644 views/vault/_init.php diff --git a/controllers/VaultController.php b/controllers/VaultController.php index c9fd156..010c200 100644 --- a/controllers/VaultController.php +++ b/controllers/VaultController.php @@ -57,7 +57,11 @@ class VaultController extends Controller public function actionIndex($directory = null): Response|string { $model = Yii::$app->user->identity; - + if ($model->vault_secret === null) { + return $this->render('_init',[ + 'model' => $model, + ]); + }//TODO $rootDataDirectory = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . Yii::$app->user->id . '.secret'; if ($directory === '.' || $directory == null) { diff --git a/models/User.php b/models/User.php index f884ed7..5467f85 100644 --- a/models/User.php +++ b/models/User.php @@ -29,6 +29,7 @@ use yii\web\IdentityInterface; * @property int|null $storage_limit 存储容量限制,MB * @property string|null $recovery_codes OTP恢复代码 * @property int|null $dark_mode 夜间模式(0 off,1 on,2 auto) + * @property string|null $vault_secret 保险箱密钥 * * @property CollectionTasks[] $collectionTasks * @property Share[] $shares @@ -44,6 +45,8 @@ class User extends ActiveRecord implements IdentityInterface public $totp_input; // otp用户输入值 public $recoveryCode_input; // 恢复代码用户输入 + public $input_vault_secret; // 保险箱密码 + /** * {@inheritdoc} */ @@ -58,10 +61,10 @@ class User extends ActiveRecord implements IdentityInterface public function rules(): array { return [ - [['status', 'is_encryption_enabled', 'is_otp_enabled','dark_mode'], 'integer'], + [['status', 'is_encryption_enabled', 'is_otp_enabled', 'dark_mode'], 'integer'], [['created_at', 'last_login'], 'safe'], - [['bio', 'totp_input','recoveryCode_input','name'], 'string'], - [['encryption_key', 'otp_secret', 'recovery_codes'], 'string', 'max' => 255], + [['bio', 'totp_input', 'recoveryCode_input', 'name'], 'string'], + [['encryption_key', 'otp_secret', 'recovery_codes', 'vault_secret', 'input_vault_secret'], 'string', 'max' => 255], [['last_login_ip'], 'string', 'max' => 45], [['username', 'password'], 'required', 'on' => 'login'], [['username', 'password', 'email', 'password2'], 'required', 'on' => 'register'], @@ -117,7 +120,8 @@ class User extends ActiveRecord implements IdentityInterface 'is_otp_enabled' => 'Is Otp Enabled', 'storage_limit' => 'Storage Limit', 'recovery_codes' => 'Recovery Codes', - 'dark_mode' =>'Dark Mode' + 'dark_mode' => 'Dark Mode', + 'vault_secret' => 'Vault Secret' ]; } diff --git a/views/vault/_gateway.php b/views/vault/_gateway.php new file mode 100644 index 0000000..95ec5b0 --- /dev/null +++ b/views/vault/_gateway.php @@ -0,0 +1,28 @@ +title = '解锁文件保险箱'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+

title) ?>

+ +

要访问文件保险箱,你必须要提供正确的保险箱密码

+ +
+
+ + field($model, 'vault_secret')->passwordInput()->label('保险箱密码(不是登陆密码)') ?> +
+ 'btn btn-primary']) ?> +
+ +
+
+
diff --git a/views/vault/_init.php b/views/vault/_init.php new file mode 100644 index 0000000..dbe74bd --- /dev/null +++ b/views/vault/_init.php @@ -0,0 +1,28 @@ +title = '初始化文件保险箱'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+

title) ?>

+ +

第一次使用文件保险箱,请在下方输入保险箱密码:

+ +
+
+ + field($model, 'input_vault_secret')->label('保险箱密码(建议不要与登陆密码相同)')->passwordInput(['autofocus' => true]) ?> +
+ 'btn btn-primary']) ?> +
+ +
+
+