2019-06-24 00:29:14 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
2020-10-28 17:51:32 +01:00
|
|
|
<!-- Group switch -->
|
|
|
|
<div class="container groups" v-if="showGroupSwitch">
|
2020-10-25 23:59:03 +01:00
|
|
|
<div class="columns is-centered">
|
|
|
|
<div class="column is-one-third-tablet is-one-quarter-desktop is-one-quarter-widescreen is-one-quarter-fullhd">
|
|
|
|
<div class="columns is-multiline">
|
2021-10-09 19:23:24 +02:00
|
|
|
<div class="column is-full" v-for="group in groups" v-if="group.twofaccounts_count > 0" :key="group.id">
|
2020-10-25 23:59:03 +01:00
|
|
|
<button :disabled="group.id == $root.appSettings.activeGroup" class="button is-fullwidth is-dark has-text-light is-outlined" @click="setActiveGroup(group.id)">{{ group.name }}</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="columns is-centered">
|
|
|
|
<div class="column has-text-centered">
|
|
|
|
<router-link :to="{ name: 'groups' }" >{{ $t('groups.manage_groups') }}</router-link>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-20 14:11:32 +01:00
|
|
|
<vue-footer :showButtons="true">
|
|
|
|
<!-- Close Group switch button -->
|
|
|
|
<p class="control">
|
|
|
|
<a class="button is-dark is-rounded" @click="closeGroupSwitch()">{{ $t('commons.close') }}</a>
|
|
|
|
</p>
|
|
|
|
</vue-footer>
|
2020-10-25 23:59:03 +01:00
|
|
|
</div>
|
2020-10-28 17:51:32 +01:00
|
|
|
<!-- Group selector -->
|
2020-11-25 21:56:04 +01:00
|
|
|
<div class="container group-selector" v-if="showGroupSelector">
|
|
|
|
<div class="columns is-centered is-multiline">
|
|
|
|
<div class="column is-full has-text-centered">
|
|
|
|
{{ $t('groups.move_selected_to') }}
|
|
|
|
</div>
|
2020-10-28 17:51:32 +01:00
|
|
|
<div class="column is-one-third-tablet is-one-quarter-desktop is-one-quarter-widescreen is-one-quarter-fullhd">
|
|
|
|
<div class="columns is-multiline">
|
|
|
|
<div class="column is-full" v-for="group in groups" :key="group.id">
|
|
|
|
<button class="button is-fullwidth is-dark has-text-light is-outlined" :class="{ 'is-link' : moveAccountsTo === group.id}" @click="moveAccountsTo = group.id">
|
2020-11-25 21:56:04 +01:00
|
|
|
<span v-if="group.id === 0" class="is-italic">
|
2020-10-28 17:51:32 +01:00
|
|
|
{{ $t('groups.no_group') }}
|
|
|
|
</span>
|
|
|
|
<span v-else>
|
|
|
|
{{ group.name }}
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-29 18:56:17 +01:00
|
|
|
<div class="columns is-centered">
|
|
|
|
<div class="column has-text-centered">
|
|
|
|
<router-link :to="{ name: 'groups' }" >{{ $t('groups.manage_groups') }}</router-link>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-28 17:51:32 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-20 14:11:32 +01:00
|
|
|
<vue-footer :showButtons="true">
|
|
|
|
<!-- Move to selected group button -->
|
|
|
|
<p class="control">
|
|
|
|
<a class="button is-link is-rounded" @click="moveAccounts()">{{ $t('commons.move') }}</a>
|
|
|
|
</p>
|
|
|
|
<!-- Cancel button -->
|
|
|
|
<p class="control">
|
|
|
|
<a class="button is-dark is-rounded" @click="showGroupSelector = false">{{ $t('commons.cancel') }}</a>
|
|
|
|
</p>
|
|
|
|
</vue-footer>
|
2020-10-28 17:51:32 +01:00
|
|
|
</div>
|
2020-04-24 09:03:00 +02:00
|
|
|
<!-- show accounts list -->
|
2020-01-08 00:39:20 +01:00
|
|
|
<div class="container" v-if="this.showAccounts">
|
2020-01-29 14:54:39 +01:00
|
|
|
<!-- accounts -->
|
2020-03-27 22:36:01 +01:00
|
|
|
<!-- <vue-pull-refresh :on-refresh="onRefresh" :config="{
|
2020-02-10 10:23:21 +01:00
|
|
|
errorLabel: 'error',
|
|
|
|
startLabel: '',
|
|
|
|
readyLabel: '',
|
|
|
|
loadingLabel: 'refreshing'
|
2020-03-27 22:36:01 +01:00
|
|
|
}" > -->
|
2020-04-24 09:03:00 +02:00
|
|
|
<draggable v-model="filteredAccounts" @start="drag = true" @end="saveOrder" ghost-class="ghost" handle=".tfa-dots" animation="200" class="accounts">
|
2020-05-02 17:55:41 +02:00
|
|
|
<transition-group class="columns is-multiline" :class="{ 'is-centered': $root.appSettings.displayMode === 'grid' }" type="transition" :name="!drag ? 'flip-list' : null">
|
|
|
|
<div :class="[$root.appSettings.displayMode === 'grid' ? 'tfa-grid' : 'tfa-list']" class="column is-narrow has-text-white" v-for="account in filteredAccounts" :key="account.id">
|
2020-03-28 15:07:42 +01:00
|
|
|
<div class="tfa-container">
|
|
|
|
<transition name="slideCheckbox">
|
2020-11-28 20:09:08 +01:00
|
|
|
<div class="tfa-cell tfa-checkbox" v-if="editMode">
|
2020-03-28 15:07:42 +01:00
|
|
|
<div class="field">
|
|
|
|
<input class="is-checkradio is-small is-white" :id="'ckb_' + account.id" :value="account.id" type="checkbox" :name="'ckb_' + account.id" v-model="selectedAccounts">
|
|
|
|
<label :for="'ckb_' + account.id"></label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
2020-11-28 20:09:08 +01:00
|
|
|
<div class="tfa-cell tfa-content is-size-3 is-size-4-mobile" @click.stop="showAccount(account)">
|
2020-03-28 15:07:42 +01:00
|
|
|
<div class="tfa-text has-ellipsis">
|
2020-10-03 19:29:14 +02:00
|
|
|
<img :src="'/storage/icons/' + account.icon" v-if="account.icon && $root.appSettings.showAccountsIcons">
|
2021-10-09 19:23:24 +02:00
|
|
|
{{ displayService(account.service) }}<font-awesome-icon class="has-text-danger is-size-5 ml-2" v-if="$root.appSettings.useEncryption && account.isConsistent === false" :icon="['fas', 'exclamation-circle']" />
|
2020-03-28 15:07:42 +01:00
|
|
|
<span class="is-family-primary is-size-6 is-size-7-mobile has-text-grey ">{{ account.account }}</span>
|
|
|
|
</div>
|
2020-03-27 22:36:01 +01:00
|
|
|
</div>
|
2020-03-28 15:07:42 +01:00
|
|
|
<transition name="fadeInOut">
|
2020-11-28 20:09:08 +01:00
|
|
|
<div class="tfa-cell tfa-edit has-text-grey" v-if="editMode">
|
2020-11-02 13:39:43 +01:00
|
|
|
<!-- <div class="tags has-addons"> -->
|
|
|
|
<router-link :to="{ name: 'editAccount', params: { twofaccountId: account.id }}" class="tag is-dark is-rounded mr-1">
|
|
|
|
{{ $t('commons.edit') }}
|
|
|
|
</router-link>
|
|
|
|
<router-link :to="{ name: 'showQRcode', params: { twofaccountId: account.id }}" class="tag is-dark is-rounded" :title="$t('twofaccounts.show_qrcode')">
|
|
|
|
<font-awesome-icon :icon="['fas', 'qrcode']" />
|
|
|
|
</router-link>
|
|
|
|
<!-- </div> -->
|
2020-03-28 15:07:42 +01:00
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
<transition name="fadeInOut">
|
2020-11-28 20:09:08 +01:00
|
|
|
<div class="tfa-cell tfa-dots has-text-grey" v-if="editMode">
|
2020-03-28 15:07:42 +01:00
|
|
|
<font-awesome-icon :icon="['fas', 'bars']" />
|
|
|
|
</div>
|
|
|
|
</transition>
|
2020-01-30 23:06:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-03-28 15:07:42 +01:00
|
|
|
</transition-group>
|
2020-03-27 22:36:01 +01:00
|
|
|
</draggable>
|
|
|
|
<!-- </vue-pull-refresh> -->
|
2020-11-20 14:11:32 +01:00
|
|
|
<vue-footer :showButtons="true">
|
|
|
|
<!-- New item buttons -->
|
|
|
|
<p class="control" v-if="!editMode">
|
|
|
|
<a class="button is-link is-rounded is-focus" @click="start">
|
|
|
|
<span>{{ $t('commons.new') }}</span>
|
|
|
|
<span class="icon is-small">
|
|
|
|
<font-awesome-icon :icon="['fas', 'qrcode']" />
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
<!-- Manage button -->
|
|
|
|
<p class="control" v-if="!editMode">
|
|
|
|
<a class="button is-dark is-rounded" @click="setEditModeTo(true)">{{ $t('commons.manage') }}</a>
|
|
|
|
</p>
|
|
|
|
<!-- Done button -->
|
|
|
|
<p class="control" v-if="editMode">
|
|
|
|
<a class="button is-success is-rounded" @click="setEditModeTo(false)">
|
|
|
|
<span>{{ $t('commons.done') }}</span>
|
|
|
|
<span class="icon is-small">
|
|
|
|
<font-awesome-icon :icon="['fas', 'check']" />
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</vue-footer>
|
2019-06-24 00:29:14 +02:00
|
|
|
</div>
|
2020-09-27 23:39:07 +02:00
|
|
|
<!-- header -->
|
2020-10-28 17:51:32 +01:00
|
|
|
<div class="header has-background-black-ter" v-if="this.showAccounts || this.showGroupSwitch">
|
2020-09-27 23:39:07 +02:00
|
|
|
<div class="columns is-gapless is-mobile is-centered">
|
|
|
|
<div class="column is-three-quarters-mobile is-one-third-tablet is-one-quarter-desktop is-one-quarter-widescreen is-one-quarter-fullhd">
|
|
|
|
<!-- toolbar -->
|
|
|
|
<div class="toolbar has-text-centered" v-if="editMode">
|
2020-09-28 00:04:17 +02:00
|
|
|
<div class="manage-buttons tags has-addons are-medium">
|
|
|
|
<span class="tag is-dark">{{ selectedAccounts.length }} {{ $t('commons.selected') }}</span>
|
2020-10-28 17:51:32 +01:00
|
|
|
<a class="tag is-link" v-if="selectedAccounts.length > 0" @click="showGroupSelector = true">
|
2020-10-25 23:59:03 +01:00
|
|
|
{{ $t('commons.move') }} <font-awesome-icon :icon="['fas', 'layer-group']" />
|
|
|
|
</a>
|
2020-09-28 00:04:17 +02:00
|
|
|
<a class="tag is-danger" v-if="selectedAccounts.length > 0" @click="destroyAccounts">
|
|
|
|
{{ $t('commons.delete') }} <font-awesome-icon :icon="['fas', 'trash']" />
|
|
|
|
</a>
|
|
|
|
</div>
|
2020-09-27 23:39:07 +02:00
|
|
|
</div>
|
|
|
|
<!-- search -->
|
|
|
|
<div class="field" v-else>
|
|
|
|
<div class="control has-icons-right">
|
|
|
|
<input type="text" class="input is-rounded is-search" v-model="search">
|
|
|
|
<span class="icon is-small is-right">
|
|
|
|
<font-awesome-icon :icon="['fas', 'search']" v-if="!search" />
|
|
|
|
<a class="delete" v-if="search" @click="search = '' "></a>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-28 17:51:32 +01:00
|
|
|
<!-- group switch toggle -->
|
|
|
|
<div class="is-clickable has-text-centered" v-if="!editMode">
|
|
|
|
<div class="columns" @click="toggleGroupSwitch">
|
|
|
|
<div class="column" v-if="!showGroupSwitch">
|
2020-11-23 12:58:44 +01:00
|
|
|
{{ activeGroupName }} ({{ filteredAccounts.length }})
|
2020-10-25 23:59:03 +01:00
|
|
|
<font-awesome-icon :icon="['fas', 'caret-down']" />
|
|
|
|
</div>
|
|
|
|
<div class="column" v-else>
|
|
|
|
{{ $t('groups.select_accounts_to_show') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-09-27 23:39:07 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-29 17:23:32 +01:00
|
|
|
<!-- modal -->
|
2020-04-24 09:03:00 +02:00
|
|
|
<modal v-model="showTwofaccountInModal">
|
2021-10-09 19:23:24 +02:00
|
|
|
<otp-displayer ref="OtpDisplayer"></otp-displayer>
|
2019-06-24 00:29:14 +02:00
|
|
|
</modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-01-19 22:31:23 +01:00
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Accounts view
|
|
|
|
*
|
|
|
|
* route: '/account' (alias: '/')
|
|
|
|
*
|
|
|
|
* The main view of 2FAuth that list all existing account recorded in DB.
|
|
|
|
* Available feature in this view :
|
2021-10-09 19:23:24 +02:00
|
|
|
* - {{OTP}} generation
|
2020-11-21 21:48:11 +01:00
|
|
|
* - Account fetching :
|
|
|
|
* ~ Search
|
|
|
|
* ~ Filtering (by group)
|
|
|
|
* - Accounts management :
|
|
|
|
* ~ Sorting
|
|
|
|
* ~ QR code recovering
|
|
|
|
* ~ Mass association to group
|
|
|
|
* ~ Mass account deletion
|
|
|
|
* ~ Access to account editing
|
|
|
|
*
|
|
|
|
* Behavior :
|
|
|
|
* - The view has 2 modes (toggle is done with the 'manage' button) :
|
|
|
|
* ~ The View mode (the default one)
|
|
|
|
* ~ The Edit mode
|
|
|
|
* - User are automatically pushed to the start view if there is no account to list.
|
|
|
|
* - The view is affected by :
|
|
|
|
* ~ 'appSettings.showAccountsIcons' toggle the icon visibility
|
|
|
|
* ~ 'appSettings.displayMode' change the account appearance
|
|
|
|
*
|
|
|
|
* Input :
|
|
|
|
* - The 'InitialEditMode' props : allows to load the view directly in Edit mode
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
import Modal from '../components/Modal'
|
2021-10-09 19:23:24 +02:00
|
|
|
import OtpDisplayer from '../components/OtpDisplayer'
|
2020-03-27 22:36:01 +01:00
|
|
|
import draggable from 'vuedraggable'
|
2020-10-25 23:59:03 +01:00
|
|
|
import Form from './../components/Form'
|
2020-11-27 15:55:02 +01:00
|
|
|
import objectEquals from 'object-equals'
|
2019-06-28 01:16:51 +02:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
export default {
|
|
|
|
data(){
|
|
|
|
return {
|
|
|
|
accounts : [],
|
2020-10-25 23:59:03 +01:00
|
|
|
groups : [],
|
2020-01-31 23:05:06 +01:00
|
|
|
selectedAccounts: [],
|
2020-01-11 16:46:59 +01:00
|
|
|
search: '',
|
2020-01-08 00:39:20 +01:00
|
|
|
editMode: this.InitialEditMode,
|
2020-11-20 14:11:32 +01:00
|
|
|
drag: false,
|
|
|
|
showTwofaccountInModal : false,
|
2020-10-28 17:51:32 +01:00
|
|
|
showGroupSwitch: false,
|
2020-10-25 23:59:03 +01:00
|
|
|
showGroupSelector: false,
|
2020-10-28 17:51:32 +01:00
|
|
|
moveAccountsTo: false,
|
2020-11-20 14:11:32 +01:00
|
|
|
form: new Form({
|
2021-10-09 19:23:24 +02:00
|
|
|
value: this.$root.appSettings.activeGroup,
|
2020-11-20 14:11:32 +01:00
|
|
|
}),
|
2019-06-24 00:29:14 +02:00
|
|
|
}
|
|
|
|
},
|
2020-01-07 15:46:48 +01:00
|
|
|
|
2020-01-11 16:46:59 +01:00
|
|
|
computed: {
|
2021-10-09 19:23:24 +02:00
|
|
|
/**
|
|
|
|
* The actual list of displayed accounts
|
|
|
|
*/
|
2020-03-27 22:36:01 +01:00
|
|
|
filteredAccounts: {
|
|
|
|
get: function() {
|
2020-11-23 12:58:44 +01:00
|
|
|
|
2020-03-27 22:36:01 +01:00
|
|
|
return this.accounts.filter(
|
|
|
|
item => {
|
2020-11-23 12:58:44 +01:00
|
|
|
if( parseInt(this.$root.appSettings.activeGroup) > 0 ) {
|
2021-10-09 19:23:24 +02:00
|
|
|
return ((item.service ? item.service.toLowerCase().includes(this.search.toLowerCase()) : false) ||
|
2020-11-23 12:58:44 +01:00
|
|
|
item.account.toLowerCase().includes(this.search.toLowerCase())) &&
|
|
|
|
(item.group_id == parseInt(this.$root.appSettings.activeGroup))
|
|
|
|
}
|
|
|
|
else {
|
2021-10-09 19:23:24 +02:00
|
|
|
return ((item.service ? item.service.toLowerCase().includes(this.search.toLowerCase()) : false) ||
|
2020-11-23 12:58:44 +01:00
|
|
|
item.account.toLowerCase().includes(this.search.toLowerCase()))
|
|
|
|
}
|
2020-03-27 22:36:01 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
set: function(reorderedAccounts) {
|
|
|
|
this.accounts = reorderedAccounts
|
|
|
|
}
|
2020-01-31 23:05:06 +01:00
|
|
|
},
|
2020-02-04 17:06:11 +01:00
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
/**
|
|
|
|
* Returns whether or not the accounts should be displayed
|
|
|
|
*/
|
2020-02-04 17:06:11 +01:00
|
|
|
showAccounts() {
|
2020-11-20 14:11:32 +01:00
|
|
|
return this.accounts.length > 0 && !this.showGroupSwitch && !this.showGroupSelector ? true : false
|
2020-02-04 17:06:11 +01:00
|
|
|
},
|
2020-04-24 09:03:00 +02:00
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
/**
|
|
|
|
* Returns the name of a group
|
|
|
|
*/
|
2020-10-25 23:59:03 +01:00
|
|
|
activeGroupName() {
|
|
|
|
let g = this.groups.find(el => el.id === parseInt(this.$root.appSettings.activeGroup))
|
|
|
|
|
|
|
|
if(g) {
|
|
|
|
return g.name
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.$t('commons.all')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-11 16:46:59 +01:00
|
|
|
},
|
|
|
|
|
2020-11-26 20:41:02 +01:00
|
|
|
props: ['initialEditMode', 'toRefresh'],
|
2020-01-07 15:46:48 +01:00
|
|
|
|
2020-04-24 09:03:00 +02:00
|
|
|
mounted() {
|
2019-06-24 00:29:14 +02:00
|
|
|
|
2020-11-27 15:55:02 +01:00
|
|
|
// we don't have to fetch fresh data so we try to load them from localstorage to avoid display latency
|
|
|
|
if( !this.toRefresh && !this.$route.params.isFirstLoad ) {
|
2020-11-26 20:41:02 +01:00
|
|
|
const accounts = this.$storage.get('accounts', null) // use null as fallback if localstorage is empty
|
2020-11-27 15:55:02 +01:00
|
|
|
if( accounts ) this.accounts = accounts
|
2020-11-26 20:41:02 +01:00
|
|
|
|
|
|
|
const groups = this.$storage.get('groups', null) // use null as fallback if localstorage is empty
|
2020-11-27 15:55:02 +01:00
|
|
|
if( groups ) this.groups = groups
|
2020-11-26 20:41:02 +01:00
|
|
|
}
|
2019-07-02 00:48:48 +02:00
|
|
|
|
2020-11-27 15:55:02 +01:00
|
|
|
// we fetch fresh data whatever. The user will be notified to reload the page if there are any data changes
|
|
|
|
this.fetchAccounts()
|
|
|
|
this.fetchGroups()
|
|
|
|
|
2020-01-07 17:05:13 +01:00
|
|
|
// stop OTP generation on modal close
|
2019-07-02 00:48:48 +02:00
|
|
|
this.$on('modalClose', function() {
|
|
|
|
console.log('modalClose triggered')
|
2021-10-09 19:23:24 +02:00
|
|
|
this.$refs.OtpDisplayer.clearOTP()
|
2019-07-02 00:48:48 +02:00
|
|
|
});
|
2020-01-07 17:05:13 +01:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
},
|
2020-01-07 15:46:48 +01:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
components: {
|
|
|
|
Modal,
|
2021-10-09 19:23:24 +02:00
|
|
|
OtpDisplayer,
|
2020-03-27 22:36:01 +01:00
|
|
|
draggable,
|
2019-06-24 00:29:14 +02:00
|
|
|
},
|
2020-01-08 00:39:20 +01:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
methods: {
|
2020-01-31 23:05:06 +01:00
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Route user to the appropriate submitting view
|
|
|
|
*/
|
2020-11-20 14:11:32 +01:00
|
|
|
start() {
|
2020-11-20 18:59:36 +01:00
|
|
|
if( this.$root.appSettings.useDirectCapture && this.$root.appSettings.defaultCaptureMode === 'advancedForm' ) {
|
|
|
|
this.$router.push({ name: 'createAccount' })
|
|
|
|
}
|
2020-11-23 19:30:58 +01:00
|
|
|
else if( this.$root.appSettings.useDirectCapture && this.$root.appSettings.defaultCaptureMode === 'livescan' ) {
|
|
|
|
this.$router.push({ name: 'capture' })
|
|
|
|
}
|
2020-11-20 18:59:36 +01:00
|
|
|
else {
|
2020-11-21 19:41:36 +01:00
|
|
|
this.$router.push({ name: 'start' })
|
2020-11-20 18:59:36 +01:00
|
|
|
}
|
2020-11-20 14:11:32 +01:00
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
2020-11-27 15:55:02 +01:00
|
|
|
* Fetch accounts from db
|
2020-11-21 21:48:11 +01:00
|
|
|
*/
|
2020-12-01 07:03:28 +01:00
|
|
|
fetchAccounts(forceRefresh = false) {
|
2020-11-27 15:55:02 +01:00
|
|
|
let accounts = []
|
2020-01-31 23:05:06 +01:00
|
|
|
this.selectedAccounts = []
|
|
|
|
|
|
|
|
this.axios.get('api/twofaccounts').then(response => {
|
|
|
|
response.data.forEach((data) => {
|
2021-10-09 19:23:24 +02:00
|
|
|
accounts.push(data)
|
2020-01-31 23:05:06 +01:00
|
|
|
})
|
2020-11-26 20:41:02 +01:00
|
|
|
|
2020-12-01 07:03:28 +01:00
|
|
|
if ( this.accounts.length > 0 && !objectEquals(accounts, this.accounts) && !forceRefresh ) {
|
2020-11-27 20:17:01 +01:00
|
|
|
this.$notify({ type: 'is-dark', text: '<span class="is-size-7">' + this.$t('commons.some_data_have_changed') + '</span><br /><a href="." class="button is-rounded is-warning is-small">' + this.$t('commons.reload') + '</a>', duration:-1, closeOnClick: false })
|
2020-11-27 15:55:02 +01:00
|
|
|
}
|
|
|
|
else if( this.accounts.length === 0 && accounts.length === 0 ) {
|
|
|
|
// No account yet, we force user to land on the start view.
|
2020-12-03 20:13:28 +01:00
|
|
|
this.$storage.set('accounts', this.accounts)
|
2020-11-21 19:41:36 +01:00
|
|
|
this.$router.push({ name: 'start' });
|
2020-11-20 14:11:32 +01:00
|
|
|
}
|
2020-11-27 15:55:02 +01:00
|
|
|
else {
|
|
|
|
this.accounts = accounts
|
|
|
|
this.$storage.set('accounts', this.accounts)
|
|
|
|
}
|
2020-01-31 23:05:06 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
2021-10-09 19:23:24 +02:00
|
|
|
* Show account with a generated {{OTP}} rotation
|
2020-11-21 21:48:11 +01:00
|
|
|
*/
|
2020-02-06 16:08:46 +01:00
|
|
|
showAccount(account) {
|
2021-10-09 19:23:24 +02:00
|
|
|
// In Edit mode clicking an account do not show the otpDisplayer but select the account
|
2020-02-06 16:08:46 +01:00
|
|
|
if(this.editMode) {
|
|
|
|
|
|
|
|
for (var i=0 ; i<this.selectedAccounts.length ; i++) {
|
|
|
|
if ( this.selectedAccounts[i] === account.id ) {
|
|
|
|
this.selectedAccounts.splice(i,1);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.selectedAccounts.push(account.id)
|
|
|
|
}
|
|
|
|
else {
|
2021-10-09 19:23:24 +02:00
|
|
|
this.$refs.OtpDisplayer.show(account.id)
|
2020-02-06 16:08:46 +01:00
|
|
|
}
|
2020-01-02 00:09:52 +01:00
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Save the account order in db
|
|
|
|
*/
|
2020-03-27 22:36:01 +01:00
|
|
|
saveOrder() {
|
2020-03-28 15:07:42 +01:00
|
|
|
this.drag = false
|
2021-10-09 19:23:24 +02:00
|
|
|
this.axios.post('/api/twofaccounts/reorder', {orderedIds: this.accounts.map(a => a.id)})
|
2020-03-27 22:36:01 +01:00
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Delete accounts selected from the Edit mode
|
|
|
|
*/
|
2020-01-31 23:05:06 +01:00
|
|
|
async destroyAccounts() {
|
|
|
|
if(confirm(this.$t('twofaccounts.confirm.delete'))) {
|
|
|
|
|
|
|
|
let ids = []
|
2020-02-06 16:08:46 +01:00
|
|
|
this.selectedAccounts.forEach(id => ids.push(id))
|
2020-01-31 23:05:06 +01:00
|
|
|
|
|
|
|
// Backend will delete all accounts at the same time
|
2021-10-09 19:23:24 +02:00
|
|
|
await this.axios.delete('/api/twofaccounts?ids=' + ids.join())
|
2020-01-31 23:05:06 +01:00
|
|
|
|
|
|
|
// we fetch the accounts again to prevent the js collection being
|
|
|
|
// desynchronize from the backend php collection
|
2020-12-01 07:03:28 +01:00
|
|
|
this.fetchAccounts(true)
|
2020-01-31 23:05:06 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
2021-10-09 19:23:24 +02:00
|
|
|
* Move accounts selected from the Edit mode to another group or withdraw them
|
2020-11-21 21:48:11 +01:00
|
|
|
*/
|
2020-10-25 23:59:03 +01:00
|
|
|
async moveAccounts() {
|
|
|
|
|
|
|
|
let accountsIds = []
|
|
|
|
this.selectedAccounts.forEach(id => accountsIds.push(id))
|
|
|
|
|
|
|
|
// Backend will associate all accounts with the selected group in the same move
|
2021-10-09 19:23:24 +02:00
|
|
|
// or withdraw the accounts if destination is 'no group' (id = 0)
|
|
|
|
if(this.moveAccountsTo === 0) {
|
|
|
|
await this.axios.patch('/api/twofaccounts/withdraw?ids=' + accountsIds.join() )
|
|
|
|
}
|
|
|
|
else await this.axios.post('/api/groups/' + this.moveAccountsTo + '/assign', {ids: accountsIds} )
|
2020-10-25 23:59:03 +01:00
|
|
|
|
|
|
|
// we fetch the accounts again to prevent the js collection being
|
|
|
|
// desynchronize from the backend php collection
|
2020-12-01 07:03:28 +01:00
|
|
|
this.fetchAccounts(true)
|
2020-10-28 17:51:32 +01:00
|
|
|
this.fetchGroups()
|
|
|
|
this.showGroupSelector = false
|
2020-10-25 23:59:03 +01:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Get the existing group list
|
|
|
|
*/
|
2020-10-25 23:59:03 +01:00
|
|
|
fetchGroups() {
|
2020-11-27 15:55:02 +01:00
|
|
|
let groups = []
|
2020-10-25 23:59:03 +01:00
|
|
|
|
|
|
|
this.axios.get('api/groups').then(response => {
|
|
|
|
response.data.forEach((data) => {
|
2021-10-09 19:23:24 +02:00
|
|
|
groups.push(data)
|
2020-10-25 23:59:03 +01:00
|
|
|
})
|
2020-11-26 20:41:02 +01:00
|
|
|
|
2020-11-27 15:55:02 +01:00
|
|
|
if ( !objectEquals(groups, this.groups) ) {
|
|
|
|
this.groups = groups
|
|
|
|
}
|
|
|
|
|
2020-11-26 20:41:02 +01:00
|
|
|
this.$storage.set('groups', this.groups)
|
2020-10-25 23:59:03 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Set the provided group as the active group
|
|
|
|
*/
|
2020-11-23 12:58:44 +01:00
|
|
|
setActiveGroup(id) {
|
2020-10-25 23:59:03 +01:00
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
// In memomry saving
|
|
|
|
this.form.value = this.$root.appSettings.activeGroup = id
|
2020-10-25 23:59:03 +01:00
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
// In db saving if the user set 2FAuth to memorize the active group
|
2020-11-23 13:01:56 +01:00
|
|
|
if( this.$root.appSettings.rememberActiveGroup ) {
|
2021-10-09 19:23:24 +02:00
|
|
|
this.form.put('/api/settings/activeGroup', {returnError: true})
|
2020-11-23 13:01:56 +01:00
|
|
|
.then(response => {
|
|
|
|
// everything's fine
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
|
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } })
|
|
|
|
});
|
|
|
|
}
|
2020-10-25 23:59:03 +01:00
|
|
|
|
2020-11-23 12:58:44 +01:00
|
|
|
this.closeGroupSwitch()
|
2020-10-25 23:59:03 +01:00
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Toggle the group switch visibility
|
|
|
|
*/
|
2020-10-28 17:51:32 +01:00
|
|
|
toggleGroupSwitch: function(event) {
|
2020-10-25 23:59:03 +01:00
|
|
|
|
|
|
|
if (event) {
|
2020-10-28 17:51:32 +01:00
|
|
|
this.showGroupSwitch ? this.closeGroupSwitch() : this.openGroupSwitch()
|
2020-10-25 23:59:03 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* show the group switch which allow to select a group to activate
|
|
|
|
*/
|
2020-10-28 17:51:32 +01:00
|
|
|
openGroupSwitch: function(event) {
|
2020-10-25 23:59:03 +01:00
|
|
|
|
2020-10-28 17:51:32 +01:00
|
|
|
this.showGroupSwitch = true
|
2020-10-25 23:59:03 +01:00
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* hide the group switch
|
|
|
|
*/
|
2020-10-28 17:51:32 +01:00
|
|
|
closeGroupSwitch: function(event) {
|
2020-10-25 23:59:03 +01:00
|
|
|
|
2020-10-28 17:51:32 +01:00
|
|
|
this.showGroupSwitch = false
|
2020-10-25 23:59:03 +01:00
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Toggle the accounts list between View mode and Edit mode
|
|
|
|
*/
|
2020-01-31 11:44:45 +01:00
|
|
|
setEditModeTo(state) {
|
2020-01-31 23:12:51 +01:00
|
|
|
if( state === false ) {
|
|
|
|
this.selectedAccounts = []
|
|
|
|
}
|
2020-02-06 16:31:05 +01:00
|
|
|
else {
|
|
|
|
this.search = '';
|
|
|
|
}
|
2020-01-31 23:12:51 +01:00
|
|
|
|
2020-01-31 11:44:45 +01:00
|
|
|
this.editMode = state
|
|
|
|
this.$parent.showToolbar = state
|
2021-10-09 19:23:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
displayService(service) {
|
|
|
|
return service ? service : this.$t('twofaccounts.no_service')
|
2020-01-27 21:13:21 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-10 17:28:30 +01:00
|
|
|
};
|
2019-06-28 01:16:51 +02:00
|
|
|
|
2020-03-28 15:07:42 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.flip-list-move {
|
|
|
|
transition: transform 0.5s;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ghost {
|
|
|
|
opacity: 1;
|
|
|
|
/*background: hsl(0, 0%, 21%);*/
|
|
|
|
}
|
|
|
|
</style>
|