From a8e5535d6be94c18f829b39b7ecf8dd175326781 Mon Sep 17 00:00:00 2001
From: Bubka <858858+Bubka@users.noreply.github.com>
Date: Mon, 2 Nov 2020 22:41:40 +0100
Subject: [PATCH] Add Default group option in Settings
---
.../Controllers/TwoFAccountController.php | 13 ++++++++++
config/app.php | 1 +
resources/js/views/settings/Options.vue | 26 +++++++++++++++++++
resources/lang/en/groups.php | 1 +
resources/lang/en/settings.php | 4 +++
5 files changed, 45 insertions(+)
diff --git a/app/Http/Controllers/TwoFAccountController.php b/app/Http/Controllers/TwoFAccountController.php
index 9072819a..25d27934 100644
--- a/app/Http/Controllers/TwoFAccountController.php
+++ b/app/Http/Controllers/TwoFAccountController.php
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
+use App\Group;
use App\TwoFAccount;
use App\Classes\OTP;
use App\Classes\Options;
@@ -47,6 +48,18 @@ class TwoFAccountController extends Controller
'icon' => $request->icon
]);
+ // Possible group association
+ $groupId = Options::get('defaultGroup') === '-1' ? (int) Options::get('activeGroup') : (int) Options::get('defaultGroup');
+
+ // 0 is the pseudo group 'All', only groups with id > 0 are true user groups
+ if( $groupId > 0 ) {
+ $group = Group::find($groupId);
+
+ if($group) {
+ $group->twofaccounts()->save($twofaccount);
+ }
+ }
+
return response()->json($twofaccount, 201);
}
diff --git a/config/app.php b/config/app.php
index bbdc65a9..d2968212 100644
--- a/config/app.php
+++ b/config/app.php
@@ -40,6 +40,7 @@ return [
'showAccountsIcons' => true,
'kickUserAfter' => '15',
'activeGroup' => 0,
+ 'defaultGroup' => 0,
'useEncryption' => false,
],
diff --git a/resources/js/views/settings/Options.vue b/resources/js/views/settings/Options.vue
index 0a502872..40f8195c 100644
--- a/resources/js/views/settings/Options.vue
+++ b/resources/js/views/settings/Options.vue
@@ -8,6 +8,8 @@
+
+
{{ $t('settings.security') }}
@@ -42,6 +44,7 @@
displayMode: this.$root.appSettings.displayMode,
kickUserAfter: this.$root.appSettings.kickUserAfter,
useEncryption: this.$root.appSettings.useEncryption,
+ defaultGroup: this.$root.appSettings.defaultGroup,
}),
langs: [
{ text: this.$t('languages.en'), value: 'en' },
@@ -61,10 +64,18 @@
{ text: this.$t('settings.forms.30_minutes'), value: '30' },
{ text: this.$t('settings.forms.1_hour'), value: '60' },
{ text: this.$t('settings.forms.1_day'), value: '1440' },
+ ],
+ groups: [
+ { text: this.$t('groups.no_group'), value: 0 },
+ { text: this.$t('groups.active_group'), value: -1 },
]
}
},
+ mounted() {
+ this.fetchGroups()
+ },
+
methods : {
handleSubmit(e) {
e.preventDefault()
@@ -86,6 +97,21 @@
this.$notify({ type: 'is-danger', text: error.response.data.message })
});
},
+
+ fetchGroups() {
+
+ this.axios.get('api/groups').then(response => {
+ response.data.forEach((data) => {
+ if( data.id >0 ) {
+ this.groups.push({
+ text: data.name,
+ value: data.id
+ })
+ }
+ })
+ })
+ },
+
},
}
\ No newline at end of file
diff --git a/resources/lang/en/groups.php b/resources/lang/en/groups.php
index 084b0ffe..48de10a2 100644
--- a/resources/lang/en/groups.php
+++ b/resources/lang/en/groups.php
@@ -16,6 +16,7 @@ return [
'groups' => 'Groups',
'select_accounts_to_show' => 'Select accounts to show',
'manage_groups' => 'Manage groups',
+ 'active_group' => 'Active group',
'manage_groups_legend' => 'You can create groups to organize your accounts the way you want. All accounts remain visible in the pseudo group named \'All\', regardless of the group they belong to.',
'deleting_group_does_not_delete_accounts' => 'Deleting a group does not delete accounts',
'no_group' => 'No group',
diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php
index faf63e0b..034d20c5 100644
--- a/resources/lang/en/settings.php
+++ b/resources/lang/en/settings.php
@@ -60,6 +60,10 @@ return [
'label' => 'Protect sensible data',
'help' => 'Sensitive data, the 2FA secrets and emails, are stored encrypted in database. Be sure to backup the APP_KEY value of your .env file (or the whole file) as it serves as key encryption. There is no way to decypher encrypted data without this key.',
],
+ 'default_group' => [
+ 'label' => 'Default group',
+ 'help' => 'The group to which the newly created accounts are associated',
+ ],
'never' => 'Never',
'on_token_copy' => 'On security code copy',
'1_minutes' => 'After 1 minute',