mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 00:03:09 +01:00
Prefill icon field with imageLink resource
This commit is contained in:
parent
b39b55fc0e
commit
101a26b035
@ -5,6 +5,7 @@
|
|||||||
use Zxing\QrReader;
|
use Zxing\QrReader;
|
||||||
use App\TwoFAccount;
|
use App\TwoFAccount;
|
||||||
use App\Classes\Options;
|
use App\Classes\Options;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use chillerlan\QRCode\{QRCode, QROptions};
|
use chillerlan\QRCode\{QRCode, QROptions};
|
||||||
@ -71,6 +72,29 @@ public function decode(Request $request)
|
|||||||
$twofaccount = new TwoFAccount;
|
$twofaccount = new TwoFAccount;
|
||||||
$twofaccount->uri = $uri;
|
$twofaccount->uri = $uri;
|
||||||
|
|
||||||
|
// When present, use the imageLink parameter to prefill the icon field
|
||||||
|
if( $twofaccount->imageLink ) {
|
||||||
|
|
||||||
|
$chunks = explode('.', $twofaccount->imageLink);
|
||||||
|
$hashFilename = Str::random(40) . '.' . end($chunks);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
Storage::disk('local')->put('imagesLink/' . $hashFilename, file_get_contents($twofaccount->imageLink));
|
||||||
|
|
||||||
|
if( in_array(Storage::mimeType('imagesLink/' . $hashFilename), ['image/png', 'image/jpeg', 'image/webp', 'image/bmp']) ) {
|
||||||
|
if( getimagesize(storage_path() . '/app/imagesLink/' . $hashFilename) ) {
|
||||||
|
|
||||||
|
Storage::move('imagesLink/' . $hashFilename, 'public/icons/' . $hashFilename);
|
||||||
|
$twofaccount->icon = $hashFilename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( Exception $e ) {
|
||||||
|
$twofaccount->imageLink = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json($twofaccount->makeVisible(['uri', 'secret', 'algorithm']), 200);
|
return response()->json($twofaccount->makeVisible(['uri', 'secret', 'algorithm']), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ public function store(Request $request)
|
|||||||
'algorithm' => 'nullable|in:sha1,sha256,sha512,md5',
|
'algorithm' => 'nullable|in:sha1,sha256,sha512,md5',
|
||||||
'totpPeriod' => 'nullable|integer|min:1',
|
'totpPeriod' => 'nullable|integer|min:1',
|
||||||
'hotpCounter' => 'nullable|integer|min:0',
|
'hotpCounter' => 'nullable|integer|min:0',
|
||||||
'imageLink' => 'nullable|url',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Two possible cases :
|
// Two possible cases :
|
||||||
@ -187,7 +186,6 @@ public function update(Request $request, $id)
|
|||||||
'algorithm' => 'nullable|in:sha1,sha256,sha512,md5',
|
'algorithm' => 'nullable|in:sha1,sha256,sha512,md5',
|
||||||
'totpPeriod' => 'required_if:otpType,totp|nullable|integer|min:1',
|
'totpPeriod' => 'required_if:otpType,totp|nullable|integer|min:1',
|
||||||
'hotpCounter' => 'required_if:otpType,hotp|nullable|integer|min:0',
|
'hotpCounter' => 'required_if:otpType,hotp|nullable|integer|min:0',
|
||||||
'imageLink' => 'nullable|url',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Here we catch a possible missing model exception in order to
|
// Here we catch a possible missing model exception in order to
|
||||||
|
@ -164,9 +164,6 @@ public function populate(Array $attrib = [])
|
|||||||
if (array_key_exists('hotpCounter', $attrib) && $attrib['hotpCounter'] && $attrib['otpType'] === 'hotp')
|
if (array_key_exists('hotpCounter', $attrib) && $attrib['hotpCounter'] && $attrib['otpType'] === 'hotp')
|
||||||
{ $this->otp->setParameter( 'counter', (int) $attrib['hotpCounter'] ); }
|
{ $this->otp->setParameter( 'counter', (int) $attrib['hotpCounter'] ); }
|
||||||
|
|
||||||
if (array_key_exists('imageLink', $attrib) && $attrib['imageLink'])
|
|
||||||
{ $this->otp->setParameter( 'image', $attrib['imageLink'] ); }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (\Exception $e) {
|
catch (\Exception $e) {
|
||||||
throw \Illuminate\Validation\ValidationException::withMessages([
|
throw \Illuminate\Validation\ValidationException::withMessages([
|
||||||
|
@ -111,8 +111,6 @@
|
|||||||
<form-field v-if="form.otpType === 'totp'" :form="form" fieldName="totpPeriod" inputType="text" :label="$t('twofaccounts.forms.totpPeriod.label')" :placeholder="$t('twofaccounts.forms.totpPeriod.placeholder')" :help="$t('twofaccounts.forms.totpPeriod.help')" />
|
<form-field v-if="form.otpType === 'totp'" :form="form" fieldName="totpPeriod" inputType="text" :label="$t('twofaccounts.forms.totpPeriod.label')" :placeholder="$t('twofaccounts.forms.totpPeriod.placeholder')" :help="$t('twofaccounts.forms.totpPeriod.help')" />
|
||||||
<!-- HOTP counter -->
|
<!-- HOTP counter -->
|
||||||
<form-field v-if="form.otpType === 'hotp'" :form="form" fieldName="hotpCounter" inputType="text" :label="$t('twofaccounts.forms.hotpCounter.label')" :placeholder="$t('twofaccounts.forms.hotpCounter.placeholder')" :help="$t('twofaccounts.forms.hotpCounter.help')" />
|
<form-field v-if="form.otpType === 'hotp'" :form="form" fieldName="hotpCounter" inputType="text" :label="$t('twofaccounts.forms.hotpCounter.label')" :placeholder="$t('twofaccounts.forms.hotpCounter.placeholder')" :help="$t('twofaccounts.forms.hotpCounter.help')" />
|
||||||
<!-- image link -->
|
|
||||||
<form-field :form="form" fieldName="imageLink" inputType="text" :label="$t('twofaccounts.forms.image_link.label')" :placeholder="$t('twofaccounts.forms.image_link.placeholder')" :help="$t('twofaccounts.forms.image_link.help')" />
|
|
||||||
</div>
|
</div>
|
||||||
<vue-footer :showButtons="true">
|
<vue-footer :showButtons="true">
|
||||||
<p class="control">
|
<p class="control">
|
||||||
@ -183,6 +181,7 @@
|
|||||||
if( this.$route.params.qrAccount ) {
|
if( this.$route.params.qrAccount ) {
|
||||||
|
|
||||||
this.form.fill(this.$route.params.qrAccount)
|
this.form.fill(this.$route.params.qrAccount)
|
||||||
|
this.tempIcon = this.$route.params.qrAccount.icon ? this.$route.params.qrAccount.icon : null
|
||||||
this.isQuickForm = true
|
this.isQuickForm = true
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -241,6 +240,7 @@
|
|||||||
|
|
||||||
this.form.fill(data)
|
this.form.fill(data)
|
||||||
this.form.secretIsBase32Encoded = 1
|
this.form.secretIsBase32Encoded = 1
|
||||||
|
this.tempIcon = data.icon ? data.icon : null
|
||||||
this.form.uri = '' // we don't want the uri because the user can change any otp parameter in the form
|
this.form.uri = '' // we don't want the uri because the user can change any otp parameter in the form
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -83,8 +83,6 @@
|
|||||||
<field-error :form="form" field="uri" class="help-for-file" />
|
<field-error :form="form" field="uri" class="help-for-file" />
|
||||||
<p class="help" v-html="$t('twofaccounts.forms.hotpCounter.help_lock')"></p>
|
<p class="help" v-html="$t('twofaccounts.forms.hotpCounter.help_lock')"></p>
|
||||||
</div>
|
</div>
|
||||||
<!-- image link -->
|
|
||||||
<form-field :form="form" fieldName="imageLink" inputType="text" :label="$t('twofaccounts.forms.image_link.label')" :placeholder="$t('twofaccounts.forms.image_link.placeholder')" :help="$t('twofaccounts.forms.image_link.help')" />
|
|
||||||
</div>
|
</div>
|
||||||
<!-- form buttons -->
|
<!-- form buttons -->
|
||||||
<vue-footer :showButtons="true">
|
<vue-footer :showButtons="true">
|
||||||
|
1
storage/app/.gitignore
vendored
1
storage/app/.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
*
|
*
|
||||||
|
!imagesLink/
|
||||||
!public/
|
!public/
|
||||||
!qrcodes/
|
!qrcodes/
|
||||||
!.gitignore
|
!.gitignore
|
||||||
|
2
storage/app/imagesLink/.gitignore
vendored
Normal file
2
storage/app/imagesLink/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
Loading…
Reference in New Issue
Block a user