Fix validation issue with migration requests

This commit is contained in:
Bubka 2022-10-10 12:55:59 +02:00
parent eb05d39210
commit a47975c46e
6 changed files with 59 additions and 5 deletions

View File

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

View File

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

View File

@ -36,4 +36,18 @@ public function rules()
'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),
]);
}
}

View File

@ -36,4 +36,18 @@ public function rules()
'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),
]);
}
}

View File

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

View File

@ -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 => {