浏览代码

Fix validation issue with migration requests

Bubka 2 年之前
父节点
当前提交
a47975c46e

+ 0 - 1
app/Api/v1/Controllers/TwoFAccountController.php

@@ -110,7 +110,6 @@ class TwoFAccountController extends Controller
      */
     public function migrate(TwoFAccountImportRequest $request)
     {
-        $request->merge(['withSecret' => true]);
         $validated = $request->validated();
 
         if (Arr::has($validated, 'file')) {

+ 14 - 0
app/Api/v1/Requests/TwoFAccountDynamicRequest.php

@@ -31,4 +31,18 @@ class TwoFAccountDynamicRequest extends FormRequest
 
         return $rules;
     }
+
+
+    /**
+     * Prepare the data for validation.
+     *
+     * @return void
+     */
+    protected function prepareForValidation()
+    {
+        $this->merge([
+            'otp_type' => strtolower($this->otp_type),
+            'algorithm' => strtolower($this->algorithm),
+        ]);
+    }
 }

+ 14 - 0
app/Api/v1/Requests/TwoFAccountStoreRequest.php

@@ -36,4 +36,18 @@ class TwoFAccountStoreRequest extends FormRequest
             'counter' => 'nullable|integer|min:0',
         ];
     }
+
+
+    /**
+     * Prepare the data for validation.
+     *
+     * @return void
+     */
+    protected function prepareForValidation()
+    {
+        $this->merge([
+            'otp_type' => strtolower($this->otp_type),
+            'algorithm' => strtolower($this->algorithm),
+        ]);
+    }
 }

+ 14 - 0
app/Api/v1/Requests/TwoFAccountUpdateRequest.php

@@ -36,4 +36,18 @@ class TwoFAccountUpdateRequest extends FormRequest
             'counter' => 'nullable|integer|min:0',
         ];
     }
+
+
+    /**
+     * Prepare the data for validation.
+     *
+     * @return void
+     */
+    protected function prepareForValidation()
+    {
+        $this->merge([
+            'otp_type' => strtolower($this->otp_type),
+            'algorithm' => strtolower($this->algorithm),
+        ]);
+    }
 }

+ 13 - 0
app/Api/v1/Requests/TwoFAccountUriRequest.php

@@ -29,4 +29,17 @@ class TwoFAccountUriRequest extends FormRequest
             'custom_otp' => 'string|in:steamtotp',
         ];
     }
+
+
+    /**
+     * Prepare the data for validation.
+     *
+     * @return void
+     */
+    protected function prepareForValidation()
+    {
+        $this->merge([
+            'custom_otp' => strtolower($this->custom_otp),
+        ]);
+    }
 }

+ 4 - 4
resources/js/views/twofaccounts/Import.vue

@@ -163,8 +163,6 @@
                     digits: null,
                     counter: null,
                     period: null,
-                    image: '',
-                    qrcode: null,
                 }),
                 uploadForm: new Form(),
                 ShowTwofaccountInModal : false,
@@ -207,7 +205,7 @@
                 this.migrationPayload = migrationPayload
                 this.isFetching = true
 
-                await this.axios.post('/api/v1/twofaccounts/migration', {payload: this.migrationPayload}, {returnError: true}).then(response => {
+                await this.axios.post('/api/v1/twofaccounts/migration', {payload: this.migrationPayload, withSecret: true}, {returnError: true}).then(response => {
                     response.data.forEach((data) => {
                         data.imported = -1;
                         this.exportedAccounts.push(data)
@@ -320,6 +318,7 @@
 
                 let filedata = new FormData();
                 filedata.append('file', this.$refs.fileInput.files[0]);
+                filedata.append('withSecret', true);
 
                 this.uploadForm.upload('/api/v1/twofaccounts/migration', filedata, {returnError: true}).then(response => {
                     response.data.forEach((data) => {
@@ -345,8 +344,9 @@
 
                 let imgdata = new FormData();
                 imgdata.append('qrcode', this.$refs.qrcodeInput.files[0]);
+                imgdata.append('withSecret', true);
 
-                this.form.upload('/api/v1/qrcode/decode', imgdata, {returnError: true}).then(response => {
+                this.uploadForm.upload('/api/v1/qrcode/decode', imgdata, {returnError: true}).then(response => {
                     this.migrate(response.data.data)
                 })
                 .catch(error => {