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']) ?> +
+ +
+
+