From 5bab7d4912d917a12016ad780ac3e975af123a3b Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Thu, 21 Jul 2022 19:07:53 +0200 Subject: [PATCH] Add a user option to disable Official icons fetching --- app/Models/TwoFAccount.php | 2 +- config/2fauth.php | 1 + resources/js/views/settings/Options.vue | 4 ++++ resources/js/views/twofaccounts/Create.vue | 27 +++++++++++----------- resources/js/views/twofaccounts/Edit.vue | 25 ++++++++++---------- resources/lang/en/settings.php | 4 ++++ 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/app/Models/TwoFAccount.php b/app/Models/TwoFAccount.php index 15689f0c..3e645ec4 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -588,7 +588,7 @@ private function getDefaultIcon() { $logoService = App::make(LogoService::class); - return $logoService->getIcon($this->service); + return SettingService::get('getOfficialIcons') ? $logoService->getIcon($this->service) : null; } diff --git a/config/2fauth.php b/config/2fauth.php index ed66ca18..77f80d2a 100644 --- a/config/2fauth.php +++ b/config/2fauth.php @@ -60,6 +60,7 @@ 'useDirectCapture' => false, 'useWebauthnAsDefault' => false, 'useWebauthnOnly' => false, + 'getOfficialIcons' => true, ], ]; \ No newline at end of file diff --git a/resources/js/views/settings/Options.vue b/resources/js/views/settings/Options.vue index cfe0fa53..a6a0289a 100644 --- a/resources/js/views/settings/Options.vue +++ b/resources/js/views/settings/Options.vue @@ -13,6 +13,9 @@ + + +

{{ $t('groups.groups') }}

@@ -87,6 +90,7 @@ useDirectCapture: null, defaultCaptureMode: '', rememberActiveGroup: true, + getOfficialIcons: null, }), layouts: [ { text: this.$t('settings.forms.grid'), value: 'grid', icon: 'th' }, diff --git a/resources/js/views/twofaccounts/Create.vue b/resources/js/views/twofaccounts/Create.vue index d1866a5e..007fe526 100644 --- a/resources/js/views/twofaccounts/Create.vue +++ b/resources/js/views/twofaccounts/Create.vue @@ -63,7 +63,7 @@
-
+
@@ -367,18 +367,19 @@ }, fetchLogo() { - - this.axios.post('/api/v1/icons/default', {service: this.form.service}, {returnError: true}).then(response => { - if (response.status === 201) { - // clean possible already uploaded temp icon - this.deleteIcon() - this.tempIcon = response.data.filename; - } - else this.$notify({type: 'is-warning', text: this.$t('errors.no_logo_found_for_x', {service: this.form.service}) }) - }) - .catch(error => { - this.$notify({type: 'is-warning', text: this.$t('errors.no_logo_found_for_x', {service: this.form.service}) }) - }); + if ($root.appSettings.getOfficialIcons) { + this.axios.post('/api/v1/icons/default', {service: this.form.service}, {returnError: true}).then(response => { + if (response.status === 201) { + // clean possible already uploaded temp icon + this.deleteIcon() + this.tempIcon = response.data.filename; + } + else this.$notify({type: 'is-warning', text: this.$t('errors.no_logo_found_for_x', {service: this.form.service}) }) + }) + .catch(error => { + this.$notify({type: 'is-warning', text: this.$t('errors.no_logo_found_for_x', {service: this.form.service}) }) + }); + } }, deleteIcon(event) { diff --git a/resources/js/views/twofaccounts/Edit.vue b/resources/js/views/twofaccounts/Edit.vue index 7b4854ca..30810073 100644 --- a/resources/js/views/twofaccounts/Edit.vue +++ b/resources/js/views/twofaccounts/Edit.vue @@ -272,18 +272,19 @@ }, fetchLogo() { - - this.axios.post('/api/v1/icons/default', {service: this.form.service}, {returnError: true}).then(response => { - if (response.status === 201) { - // clean possible already uploaded temp icon - this.deleteIcon() - this.tempIcon = response.data.filename; - } - else this.$notify({type: 'is-warning', text: this.$t('errors.no_logo_found_for_x', {service: this.form.service}) }) - }) - .catch(error => { - this.$notify({type: 'is-warning', text: this.$t('errors.no_logo_found_for_x', {service: this.form.service}) }) - }); + if ($root.appSettings.getOfficialIcons) { + this.axios.post('/api/v1/icons/default', {service: this.form.service}, {returnError: true}).then(response => { + if (response.status === 201) { + // clean possible already uploaded temp icon + this.deleteIcon() + this.tempIcon = response.data.filename; + } + else this.$notify({type: 'is-warning', text: this.$t('errors.no_logo_found_for_x', {service: this.form.service}) }) + }) + .catch(error => { + this.$notify({type: 'is-warning', text: this.$t('errors.no_logo_found_for_x', {service: this.form.service}) }) + }); + } }, deleteIcon(event) { diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index f5eaa5e9..72b803e8 100644 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -70,6 +70,10 @@ 'label' => 'Show icons', 'help' => 'Show icons accounts in the main view' ], + 'get_official_icons' => [ + 'label' => 'Get official icons', + 'help' => '(Try to) Get the official icon of the 2FA issuer when adding an account' + ], 'auto_lock' => [ 'label' => 'Auto lock', 'help' => 'Log out the user automatically in case of inactivity. Has no effect when authentication is handled by a proxy and no custom logout url is specified.'