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">
|
2023-02-01 17:21:55 +01:00
|
|
|
<button class="button is-fullwidth" :class="{'is-dark has-text-light is-outlined':$root.showDarkMode}" @click="setActiveGroup(group.id)">{{ group.name }}</button>
|
2020-10-25 23:59:03 +01:00
|
|
|
</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">
|
2023-02-01 17:21:55 +01:00
|
|
|
<button class="button is-rounded" :class="{'is-dark' : $root.showDarkMode}" @click="closeGroupSwitch()">{{ $t('commons.close') }}</button>
|
2020-11-20 14:11:32 +01:00
|
|
|
</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">
|
2023-02-01 17:21:55 +01:00
|
|
|
<button class="button is-fullwidth" :class="{'is-link' : moveAccountsTo === group.id, 'is-dark has-text-light is-outlined':$root.showDarkMode}" @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">
|
2022-09-17 19:31:11 +02:00
|
|
|
<button class="button is-link is-rounded" @click="moveAccounts()">{{ $t('commons.move') }}</button>
|
2020-11-20 14:11:32 +01:00
|
|
|
</p>
|
|
|
|
<!-- Cancel button -->
|
|
|
|
<p class="control">
|
2023-02-01 17:21:55 +01:00
|
|
|
<button class="button is-rounded" :class="{'is-dark' : $root.showDarkMode}" @click="showGroupSelector = false">{{ $t('commons.cancel') }}</button>
|
2020-11-20 14:11:32 +01:00
|
|
|
</p>
|
|
|
|
</vue-footer>
|
2020-10-28 17:51:32 +01:00
|
|
|
</div>
|
2022-10-12 11:30:20 +02:00
|
|
|
<!-- header -->
|
2023-02-01 17:21:55 +01:00
|
|
|
<div class="header" v-if="this.showAccounts || this.showGroupSwitch">
|
2022-10-12 11:30:20 +02:00
|
|
|
<div class="columns is-gapless is-mobile is-centered">
|
2022-12-14 14:00:33 +01:00
|
|
|
<div class="column is-three-quarters-mobile is-one-third-tablet is-one-quarter-desktop is-one-quarter-widescreen is-one-quarter-fullhd">
|
|
|
|
<!-- search -->
|
|
|
|
<div role="search" class="field">
|
|
|
|
<div class="control has-icons-right">
|
2023-02-08 16:05:45 +01:00
|
|
|
<input ref="searchBox" id="txtSearch" type="search" tabindex="1" :aria-label="$t('commons.search')" :title="$t('commons.search')" class="input is-rounded is-search" v-model="search">
|
2022-12-14 14:00:33 +01:00
|
|
|
<span class="icon is-small is-right">
|
|
|
|
<font-awesome-icon :icon="['fas', 'search']" v-if="!search" />
|
|
|
|
<button tabindex="1" :title="$t('commons.clear_search')" class="clear-selection delete" v-if="search" @click="search = '' "></button>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-12 11:30:20 +02:00
|
|
|
<!-- toolbar -->
|
2022-12-14 14:00:33 +01:00
|
|
|
<div v-if="editMode" class="toolbar has-text-centered">
|
|
|
|
<div class="columns">
|
|
|
|
<div class="column">
|
|
|
|
<!-- selected label -->
|
2023-02-01 17:21:55 +01:00
|
|
|
<span class="has-text-grey mr-1">{{ selectedAccounts.length }} {{ $t('commons.selected') }}</span>
|
2022-12-14 14:00:33 +01:00
|
|
|
<!-- deselect all -->
|
|
|
|
<button @click="clearSelected" class="clear-selection delete mr-4" :style="{visibility: selectedAccounts.length > 0 ? 'visible' : 'hidden'}" :title="$t('commons.clear_selection')"></button>
|
|
|
|
<!-- select all button -->
|
2023-02-01 17:21:55 +01:00
|
|
|
<button @click="selectAll" class="button mr-5 has-line-height p-1 is-ghost has-text-grey" :title="$t('commons.select_all')">
|
2022-10-12 11:30:20 +02:00
|
|
|
<span>{{ $t('commons.all') }}</span>
|
|
|
|
<font-awesome-icon class="ml-1" :icon="['fas', 'check-square']" />
|
|
|
|
</button>
|
2022-12-14 14:00:33 +01:00
|
|
|
<!-- sort asc/desc buttons -->
|
2023-02-01 17:21:55 +01:00
|
|
|
<button @click="sortAsc" class="button has-line-height p-1 is-ghost has-text-grey" :title="$t('commons.sort_ascending')">
|
2022-10-12 11:30:20 +02:00
|
|
|
<font-awesome-icon :icon="['fas', 'sort-alpha-down']" />
|
|
|
|
</button>
|
2023-02-01 17:21:55 +01:00
|
|
|
<button @click="sortDesc" class="button has-line-height p-1 is-ghost has-text-grey" :title="$t('commons.sort_descending')">
|
2022-10-12 11:30:20 +02:00
|
|
|
<font-awesome-icon :icon="['fas', 'sort-alpha-up']" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- group switch toggle -->
|
2022-12-14 14:00:33 +01:00
|
|
|
<div v-else class="has-text-centered">
|
2022-10-12 11:30:20 +02:00
|
|
|
<div class="columns">
|
|
|
|
<div class="column" v-if="!showGroupSwitch">
|
2023-02-01 17:21:55 +01:00
|
|
|
<button :title="$t('groups.show_group_selector')" tabindex="1" class="button is-text is-like-text" :class="{'has-text-grey' : !$root.showDarkMode}" @click.stop="toggleGroupSwitch">
|
2022-10-12 11:30:20 +02:00
|
|
|
{{ activeGroupName }} ({{ filteredAccounts.length }})
|
|
|
|
<font-awesome-icon :icon="['fas', 'caret-down']" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="column" v-else>
|
2023-02-01 17:21:55 +01:00
|
|
|
<button :title="$t('groups.hide_group_selector')" tabindex="1" class="button is-text is-like-text" :class="{'has-text-grey' : !$root.showDarkMode}" @click.stop="toggleGroupSwitch">
|
2022-10-12 11:30:20 +02:00
|
|
|
{{ $t('groups.select_accounts_to_show') }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- modal -->
|
|
|
|
<modal v-model="showTwofaccountInModal">
|
|
|
|
<otp-displayer ref="OtpDisplayer"></otp-displayer>
|
|
|
|
</modal>
|
2020-04-24 09:03:00 +02:00
|
|
|
<!-- show accounts list -->
|
2022-10-12 11:30:20 +02:00
|
|
|
<div class="container" v-if="this.showAccounts" :class="editMode ? 'is-edit-mode' : ''">
|
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">
|
2023-02-17 17:12:53 +01:00
|
|
|
<transition-group class="columns is-multiline" :class="{ 'is-centered': $root.userPreferences.displayMode === 'grid' }" type="transition" :name="!drag ? 'flip-list' : null">
|
|
|
|
<div :class="[$root.userPreferences.displayMode === 'grid' ? 'tfa-grid' : 'tfa-list']" class="column is-narrow" 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">
|
2023-02-01 17:21:55 +01:00
|
|
|
<input class="is-checkradio is-small" :class="$root.showDarkMode ? 'is-white':'is-info'" :id="'ckb_' + account.id" :value="account.id" type="checkbox" :name="'ckb_' + account.id" v-model="selectedAccounts">
|
2022-10-12 11:30:20 +02:00
|
|
|
<label tabindex="0" :for="'ckb_' + account.id" v-on:keypress.space.prevent="selectAccount(account.id)"></label>
|
2020-03-28 15:07:42 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
2023-04-14 17:13:28 +02:00
|
|
|
<div tabindex="0" class="tfa-cell tfa-content is-size-3 is-size-4-mobile" @click="showOrCopy(account)" @keyup.enter="showOrCopy(account)" role="button">
|
2020-03-28 15:07:42 +01:00
|
|
|
<div class="tfa-text has-ellipsis">
|
2023-02-17 17:12:53 +01:00
|
|
|
<img :src="$root.appConfig.subdirectory + '/storage/icons/' + account.icon" v-if="account.icon && $root.userPreferences.showAccountsIcons" :alt="$t('twofaccounts.icon_for_account_x_at_service_y', {account: account.account, service: account.service})">
|
2021-10-11 23:11:52 +02:00
|
|
|
{{ displayService(account.service) }}<font-awesome-icon class="has-text-danger is-size-5 ml-2" v-if="$root.appSettings.useEncryption && account.account === $t('errors.indecipherable')" :icon="['fas', 'exclamation-circle']" />
|
2023-04-14 17:13:28 +02:00
|
|
|
<span class="has-ellipsis is-family-primary is-size-6 is-size-7-mobile has-text-grey ">{{ account.account }}</span>
|
2020-03-28 15:07:42 +01:00
|
|
|
</div>
|
2020-03-27 22:36:01 +01:00
|
|
|
</div>
|
2023-04-14 17:13:28 +02:00
|
|
|
<transition name="popLater">
|
|
|
|
<div v-show="$root.userPreferences.getOtpOnRequest == false && !editMode" class="has-text-right">
|
2023-07-06 09:00:14 +02:00
|
|
|
<span v-if="account.otp != undefined && isRenewingOTPs" class="has-nowrap has-text-grey has-text-centered is-size-5">
|
2023-06-30 17:31:05 +02:00
|
|
|
<font-awesome-icon :icon="['fas', 'circle-notch']" spin />
|
|
|
|
</span>
|
2023-07-06 09:00:14 +02:00
|
|
|
<span v-else-if="account.otp != undefined && isRenewingOTPs == false" class="is-clickable has-nowrap has-text-grey is-size-5 ml-4" @click="copyOTP(account.otp.password)" @keyup.enter="copyOTP(account.otp.password)" :title="$t('commons.copy_to_clipboard')">
|
|
|
|
{{ displayPwd(account.otp.password) }}
|
|
|
|
</span>
|
2023-04-14 17:13:28 +02:00
|
|
|
<span v-else>
|
|
|
|
<!-- get hotp button -->
|
|
|
|
<button class="button tag" :class="$root.showDarkMode ? 'is-dark' : 'is-white'" @click="showAccount(account)" :title="$t('twofaccounts.import.import_this_account')">
|
|
|
|
{{ $t('commons.generate') }}
|
|
|
|
</button>
|
|
|
|
</span>
|
2023-05-29 11:33:30 +02:00
|
|
|
<dots v-if="account.otp_type.includes('totp')" @hook:mounted="turnDotsOnFromCache(account.period)" :class="'condensed'" :ref="'dots_' + account.period"></dots>
|
2023-04-14 17:13:28 +02:00
|
|
|
</div>
|
|
|
|
</transition>
|
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">
|
2023-04-14 17:13:28 +02:00
|
|
|
<router-link :to="{ name: 'editAccount', params: { twofaccountId: account.id }}" class="tag is-rounded mr-1" :class="$root.showDarkMode ? 'is-dark' : 'is-white'">
|
|
|
|
{{ $t('commons.edit') }}
|
|
|
|
</router-link>
|
|
|
|
<router-link :to="{ name: 'showQRcode', params: { twofaccountId: account.id }}" class="tag is-rounded" :class="$root.showDarkMode ? 'is-dark' : 'is-white'" :title="$t('twofaccounts.show_qrcode')">
|
|
|
|
<font-awesome-icon :icon="['fas', 'qrcode']" />
|
|
|
|
</router-link>
|
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>
|
2023-04-14 17:13:28 +02:00
|
|
|
<!-- <twofaccount v-for="account in filteredAccounts" :account="account" :key="account.id" :selectedAccounts="selectedAccounts" :isEditMode="editMode" v-on:selected="selectAccount" v-on:show="showAccount"></twofaccount> -->
|
2020-03-28 15:07:42 +01:00
|
|
|
</transition-group>
|
2020-03-27 22:36:01 +01:00
|
|
|
</draggable>
|
|
|
|
<!-- </vue-pull-refresh> -->
|
2022-12-14 14:00:33 +01:00
|
|
|
<vue-footer :showButtons="true" :editMode="editMode" v-on:exit-edit="setEditModeTo(false)">
|
2020-11-20 14:11:32 +01:00
|
|
|
<!-- New item buttons -->
|
|
|
|
<p class="control" v-if="!editMode">
|
2022-09-17 19:31:11 +02:00
|
|
|
<button class="button is-link is-rounded is-focus" @click="start">
|
2020-11-20 14:11:32 +01:00
|
|
|
<span>{{ $t('commons.new') }}</span>
|
|
|
|
<span class="icon is-small">
|
|
|
|
<font-awesome-icon :icon="['fas', 'qrcode']" />
|
|
|
|
</span>
|
2022-09-17 19:31:11 +02:00
|
|
|
</button>
|
2020-11-20 14:11:32 +01:00
|
|
|
</p>
|
|
|
|
<!-- Manage button -->
|
|
|
|
<p class="control" v-if="!editMode">
|
2023-02-01 17:21:55 +01:00
|
|
|
<button class="button is-rounded" :class="{'is-dark' : $root.showDarkMode}" @click="setEditModeTo(true)">{{ $t('commons.manage') }}</button>
|
2020-11-20 14:11:32 +01:00
|
|
|
</p>
|
2022-12-14 14:00:33 +01:00
|
|
|
<!-- move button -->
|
2020-11-20 14:11:32 +01:00
|
|
|
<p class="control" v-if="editMode">
|
2023-04-24 08:10:13 +02:00
|
|
|
<button
|
|
|
|
:disabled='selectedAccounts.length == 0' class="button is-rounded"
|
|
|
|
:class="[{'is-outlined': $root.showDarkMode||selectedAccounts.length == 0}, selectedAccounts.length == 0 ? 'is-dark': 'is-link']"
|
2022-12-14 14:00:33 +01:00
|
|
|
@click="showGroupSelector = true"
|
|
|
|
:title="$t('groups.move_selected_to_group')" >
|
|
|
|
{{ $t('commons.move') }}
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
<!-- delete button -->
|
|
|
|
<p class="control" v-if="editMode">
|
2023-04-24 08:10:13 +02:00
|
|
|
<button
|
|
|
|
:disabled='selectedAccounts.length == 0' class="button is-rounded"
|
|
|
|
:class="[{'is-outlined': $root.showDarkMode||selectedAccounts.length == 0}, selectedAccounts.length == 0 ? 'is-dark': 'is-link']"
|
2022-12-14 14:00:33 +01:00
|
|
|
@click="destroyAccounts" >
|
|
|
|
{{ $t('commons.delete') }}
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
<!-- export button -->
|
|
|
|
<p class="control" v-if="editMode">
|
2023-04-24 08:10:13 +02:00
|
|
|
<button
|
|
|
|
:disabled='selectedAccounts.length == 0' class="button is-rounded"
|
|
|
|
:class="[{'is-outlined': $root.showDarkMode||selectedAccounts.length == 0}, selectedAccounts.length == 0 ? 'is-dark': 'is-link']"
|
|
|
|
@click="exportAccounts"
|
2022-12-14 14:00:33 +01:00
|
|
|
:title="$t('twofaccounts.export_selected_to_json')" >
|
|
|
|
{{ $t('commons.export') }}
|
2022-09-17 19:31:11 +02:00
|
|
|
</button>
|
2020-11-20 14:11:32 +01:00
|
|
|
</p>
|
|
|
|
</vue-footer>
|
2019-06-24 00:29:14 +02:00
|
|
|
</div>
|
2023-04-14 17:13:28 +02:00
|
|
|
<span v-if="!this.$root.userPreferences.getOtpOnRequest">
|
2023-05-29 11:33:30 +02:00
|
|
|
<totp-looper
|
|
|
|
v-for="period in periods"
|
|
|
|
:key="period.period"
|
|
|
|
:period="period.period"
|
|
|
|
:generated_at="period.generated_at"
|
2023-04-14 17:13:28 +02:00
|
|
|
v-on:loop-ended="updateTotps(period.period)"
|
2023-05-29 11:33:30 +02:00
|
|
|
v-on:loop-started="setCurrentStep(period.period, $event)"
|
|
|
|
v-on:stepped-up="setCurrentStep(period.period, $event)"
|
2023-04-14 17:13:28 +02:00
|
|
|
ref="loopers"
|
|
|
|
></totp-looper>
|
|
|
|
</span>
|
2019-06-24 00:29:14 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-01-19 22:31:23 +01:00
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Accounts view
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2020-11-21 21:48:11 +01:00
|
|
|
* route: '/account' (alias: '/')
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2020-11-21 21:48:11 +01:00
|
|
|
* 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 :
|
2023-02-17 17:12:53 +01:00
|
|
|
* ~ 'userPreferences.showAccountsIcons' toggle the icon visibility
|
|
|
|
* ~ 'userPreferences.displayMode' change the account appearance
|
2020-11-21 21:48:11 +01:00
|
|
|
*
|
2023-04-24 08:10:13 +02:00
|
|
|
* Input :
|
2022-09-17 19:34:19 +02:00
|
|
|
* - The 'initialEditMode' props : allows to load the view directly in Edit mode
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2020-11-21 21:48:11 +01:00
|
|
|
*/
|
|
|
|
|
2023-04-14 17:13:28 +02:00
|
|
|
// import Twofaccount from '../components/Twofaccount'
|
2019-06-24 00:29:14 +02:00
|
|
|
import Modal from '../components/Modal'
|
2023-04-14 17:13:28 +02:00
|
|
|
import TotpLooper from '../components/TotpLooper'
|
|
|
|
import Dots from '../components/Dots'
|
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'
|
2022-12-13 15:57:33 +01:00
|
|
|
import { saveAs } from 'file-saver';
|
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: '',
|
2022-09-17 19:34:19 +02: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({
|
2023-02-17 17:12:53 +01:00
|
|
|
value: this.$root.userPreferences.activeGroup,
|
2020-11-20 14:11:32 +01:00
|
|
|
}),
|
2023-06-30 17:31:05 +02:00
|
|
|
stepIndexes: {},
|
|
|
|
isRenewingOTPs: false
|
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 => {
|
2023-02-17 17:12:53 +01:00
|
|
|
if( parseInt(this.$root.userPreferences.activeGroup) > 0 ) {
|
2023-04-24 08:10:13 +02:00
|
|
|
return ((item.service ? item.service.toLowerCase().includes(this.search.toLowerCase()) : false) ||
|
|
|
|
item.account.toLowerCase().includes(this.search.toLowerCase())) &&
|
2023-02-17 17:12:53 +01:00
|
|
|
(item.group_id == parseInt(this.$root.userPreferences.activeGroup))
|
2020-11-23 12:58:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2023-04-24 08:10:13 +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() {
|
2023-02-17 17:12:53 +01:00
|
|
|
let g = this.groups.find(el => el.id === parseInt(this.$root.userPreferences.activeGroup))
|
2020-10-25 23:59:03 +01:00
|
|
|
|
|
|
|
if(g) {
|
|
|
|
return g.name
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.$t('commons.all')
|
|
|
|
}
|
2023-04-14 17:13:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of all totp periods present in the twofaccounts list
|
|
|
|
*/
|
|
|
|
periods() {
|
|
|
|
return !this.$root.userPreferences.getOtpOnRequest ?
|
|
|
|
this.accounts.filter(acc => acc.otp_type == 'totp').map(function(item) {
|
|
|
|
return {period: item.period, generated_at: item.otp.generated_at}
|
|
|
|
// return item.period
|
|
|
|
}).filter((value, index, self) => index === self.findIndex((t) => (
|
|
|
|
t.period === value.period
|
|
|
|
))).sort()
|
|
|
|
: null
|
|
|
|
},
|
2020-10-25 23:59:03 +01:00
|
|
|
|
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
|
|
|
|
2023-02-08 16:05:45 +01:00
|
|
|
document.addEventListener('keydown', this.keyListener)
|
|
|
|
|
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
|
2023-04-14 17:13:28 +02:00
|
|
|
if( this.$root.userPreferences.getOtpOnRequest && !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()
|
|
|
|
|
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() {
|
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
|
|
|
|
2023-02-08 16:05:45 +01:00
|
|
|
destroyed () {
|
|
|
|
document.removeEventListener('keydown', this.keyListener)
|
|
|
|
},
|
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
components: {
|
2023-04-14 17:13:28 +02:00
|
|
|
// Twofaccount,
|
2019-06-24 00:29:14 +02:00
|
|
|
Modal,
|
2021-10-09 19:23:24 +02:00
|
|
|
OtpDisplayer,
|
2023-04-14 17:13:28 +02:00
|
|
|
TotpLooper,
|
|
|
|
Dots,
|
|
|
|
draggable,
|
2019-06-24 00:29:14 +02:00
|
|
|
},
|
2020-01-08 00:39:20 +01:00
|
|
|
|
2023-04-14 17:13:28 +02:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
methods: {
|
2020-01-31 23:05:06 +01:00
|
|
|
|
2023-04-14 17:13:28 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
showOrCopy(account) {
|
|
|
|
if (!this.$root.userPreferences.getOtpOnRequest && account.otp_type.includes('totp')) {
|
|
|
|
this.copyOTP(account.otp.password)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.showAccount(account)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
copyOTP (otp) {
|
|
|
|
// see https://web.dev/async-clipboard/ for futur Clipboard API usage.
|
|
|
|
// The API should allow to copy the password on each trip without user interaction.
|
|
|
|
|
|
|
|
// For now too many browsers don't support the clipboard-write permission
|
|
|
|
// (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions#browser_support)
|
|
|
|
|
|
|
|
const success = this.$clipboard(otp)
|
|
|
|
|
|
|
|
if (success == true) {
|
|
|
|
if(this.$root.userPreferences.kickUserAfter == -1) {
|
|
|
|
this.appLogout()
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$notify({ type: 'is-success', text: this.$t('commons.copied_to_clipboard') })
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-05-29 11:33:30 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
setCurrentStep(period, stepIndex) {
|
|
|
|
this.stepIndexes[period] = stepIndex
|
|
|
|
this.turnDotsOn(period, stepIndex)
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
turnDotsOnFromCache(period, stepIndex) {
|
|
|
|
if (this.stepIndexes[period] != undefined) {
|
|
|
|
this.turnDotsOn(period, this.stepIndexes[period])
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-04-14 17:13:28 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
turnDotsOn(period, stepIndex) {
|
|
|
|
this.$refs['dots_' + period].forEach((dots) => {
|
|
|
|
dots.turnOn(stepIndex)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch all accounts set with the given period to get fresh OTPs
|
|
|
|
*/
|
|
|
|
async updateTotps(period) {
|
2023-06-30 17:31:05 +02:00
|
|
|
this.isRenewingOTPs = true
|
2023-04-14 17:13:28 +02:00
|
|
|
this.axios.get('api/v1/twofaccounts?withOtp=1&ids=' + this.accountIdsWithPeriod(period).join(',')).then(response => {
|
|
|
|
response.data.forEach((account) => {
|
|
|
|
const index = this.accounts.findIndex(acc => acc.id === account.id)
|
|
|
|
this.accounts[index].otp = account.otp
|
|
|
|
|
|
|
|
this.$refs.loopers.forEach((looper) => {
|
|
|
|
if (looper.period == period) {
|
|
|
|
looper.generatedAt = account.otp.generated_at
|
2023-05-29 11:33:30 +02:00
|
|
|
this.$nextTick(() => {
|
|
|
|
looper.startLoop()
|
|
|
|
})
|
2023-04-14 17:13:28 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2023-06-30 17:31:05 +02:00
|
|
|
.finally(() => {
|
|
|
|
this.isRenewingOTPs = false
|
|
|
|
})
|
2023-04-14 17:13:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of all accounts (ids) set with the given period
|
|
|
|
*/
|
|
|
|
accountIdsWithPeriod(period) {
|
|
|
|
return this.accounts.filter(a => a.period == period).map(item => item.id)
|
|
|
|
},
|
|
|
|
|
2020-11-21 21:48:11 +01:00
|
|
|
/**
|
|
|
|
* Route user to the appropriate submitting view
|
|
|
|
*/
|
2020-11-20 14:11:32 +01:00
|
|
|
start() {
|
2023-02-17 17:12:53 +01:00
|
|
|
if( this.$root.userPreferences.useDirectCapture && this.$root.userPreferences.defaultCaptureMode === 'advancedForm' ) {
|
2020-11-20 18:59:36 +01:00
|
|
|
this.$router.push({ name: 'createAccount' })
|
|
|
|
}
|
2023-02-17 17:12:53 +01:00
|
|
|
else if( this.$root.userPreferences.useDirectCapture && this.$root.userPreferences.defaultCaptureMode === 'livescan' ) {
|
2020-11-23 19:30:58 +01:00
|
|
|
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 = []
|
2023-04-14 17:13:28 +02:00
|
|
|
const queryParam = this.$root.userPreferences.getOtpOnRequest ? '' : '?withOtp=1'
|
|
|
|
// const queryParam = '?withOtp=1'
|
2020-01-31 23:05:06 +01:00
|
|
|
|
2023-04-14 17:13:28 +02:00
|
|
|
this.axios.get('api/v1/twofaccounts' + queryParam).then(response => {
|
2020-01-31 23:05:06 +01:00
|
|
|
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
|
|
|
|
2023-05-29 11:33:30 +02:00
|
|
|
if ( this.accounts.length > 0 && !objectEquals(accounts, this.accounts, {depth: 1}) && !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)
|
2022-05-19 14:05:34 +02:00
|
|
|
this.fetchGroups()
|
2020-11-27 15:55:02 +01:00
|
|
|
}
|
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) {
|
2022-10-14 14:16:16 +02:00
|
|
|
this.selectAccount(account.id)
|
2020-02-06 16:08:46 +01:00
|
|
|
}
|
|
|
|
else {
|
2023-04-24 13:09:50 +02:00
|
|
|
this.$root.showSpinner(this.$t('commons.generating_otp'));
|
2023-04-24 09:30:23 +02:00
|
|
|
this.$refs.OtpDisplayer.show(account.id);
|
2020-02-06 16:08:46 +01:00
|
|
|
}
|
2020-01-02 00:09:52 +01:00
|
|
|
},
|
2023-04-24 13:09:50 +02:00
|
|
|
|
2022-10-12 11:30:20 +02:00
|
|
|
/**
|
|
|
|
* Select an account while in edit mode
|
|
|
|
*/
|
|
|
|
selectAccount(accountId) {
|
|
|
|
for (var i=0 ; i<this.selectedAccounts.length ; i++) {
|
|
|
|
if ( this.selectedAccounts[i] === accountId ) {
|
|
|
|
this.selectedAccounts.splice(i,1);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.selectedAccounts.push(accountId)
|
|
|
|
},
|
|
|
|
|
2022-09-21 21:50:41 +02:00
|
|
|
/**
|
|
|
|
* Get a fresh OTP for the provided account
|
|
|
|
*/
|
|
|
|
getOTP(accountId) {
|
|
|
|
this.axios.get('api/v1/twofaccounts/' + accountId + '/otp').then(response => {
|
|
|
|
this.$notify({ type: 'is-success', text: this.$t('commons.copied_to_clipboard')+ ' '+response.data })
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
|
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-11-07 21:57:22 +01:00
|
|
|
this.axios.post('/api/v1/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
|
|
|
|
2022-06-20 22:40:35 +02:00
|
|
|
let that = this
|
2021-11-07 21:57:22 +01:00
|
|
|
await this.axios.delete('/api/v1/twofaccounts?ids=' + ids.join())
|
2022-06-20 22:40:35 +02:00
|
|
|
.then(response => {
|
|
|
|
ids.forEach(function(id) {
|
|
|
|
that.accounts = that.accounts.filter(a => a.id !== id)
|
|
|
|
})
|
2022-09-19 12:19:34 +02:00
|
|
|
this.$notify({ type: 'is-success', text: this.$t('twofaccounts.accounts_deleted') })
|
2022-06-20 22:40:35 +02:00
|
|
|
})
|
2023-04-24 08:10:13 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-12-13 15:57:33 +01:00
|
|
|
/**
|
|
|
|
* Export selected accounts
|
|
|
|
*/
|
|
|
|
exportAccounts() {
|
|
|
|
let ids = []
|
|
|
|
this.selectedAccounts.forEach(id => ids.push(id))
|
|
|
|
|
|
|
|
this.axios.get('/api/v1/twofaccounts/export?ids=' + ids.join(), {responseType: 'blob'})
|
|
|
|
.then((response) => {
|
|
|
|
var blob = new Blob([response.data], {type: "application/json;charset=utf-8"});
|
|
|
|
saveAs.saveAs(blob, "2fauth_export.json");
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
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) {
|
2021-11-07 21:57:22 +01:00
|
|
|
await this.axios.patch('/api/v1/twofaccounts/withdraw?ids=' + accountsIds.join() )
|
2021-10-09 19:23:24 +02:00
|
|
|
}
|
2021-11-07 21:57:22 +01:00
|
|
|
else await this.axios.post('/api/v1/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.showGroupSelector = false
|
2020-10-25 23:59:03 +01:00
|
|
|
|
2022-09-19 12:19:34 +02:00
|
|
|
this.$notify({ type: 'is-success', text: this.$t('twofaccounts.accounts_moved') })
|
|
|
|
|
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
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
this.axios.get('api/v1/groups').then(response => {
|
2020-10-25 23:59:03 +01:00
|
|
|
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
|
2023-04-24 08:10:13 +02:00
|
|
|
}
|
2020-11-27 15:55:02 +01:00
|
|
|
|
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
|
2023-02-17 17:12:53 +01:00
|
|
|
this.form.value = this.$root.userPreferences.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
|
2023-02-17 17:12:53 +01:00
|
|
|
if( this.$root.userPreferences.rememberActiveGroup ) {
|
2023-02-25 22:24:44 +01:00
|
|
|
this.form.put('/api/v1/user/preferences/activeGroup', {returnError: true})
|
2020-11-23 13:01:56 +01:00
|
|
|
.then(response => {
|
|
|
|
// everything's fine
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2023-04-24 08:10:13 +02:00
|
|
|
|
2020-11-23 13:01:56 +01:00
|
|
|
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) {
|
2022-12-14 14:00:33 +01:00
|
|
|
this.selectedAccounts = []
|
2020-01-31 11:44:45 +01:00
|
|
|
this.editMode = state
|
2021-10-09 19:23:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2021-10-09 19:23:24 +02:00
|
|
|
*/
|
|
|
|
displayService(service) {
|
|
|
|
return service ? service : this.$t('twofaccounts.no_service')
|
2022-07-28 13:16:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2022-07-28 13:16:05 +02:00
|
|
|
*/
|
|
|
|
clearSelected() {
|
|
|
|
this.selectedAccounts = []
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2022-07-28 13:16:05 +02:00
|
|
|
*/
|
|
|
|
selectAll() {
|
|
|
|
if(this.editMode) {
|
|
|
|
let that = this
|
|
|
|
this.accounts.forEach(function(account) {
|
|
|
|
if ( !that.selectedAccounts.includes(account.id) ) {
|
|
|
|
that.selectedAccounts.push(account.id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2022-07-28 13:16:05 +02:00
|
|
|
*/
|
|
|
|
sortAsc() {
|
|
|
|
this.accounts.sort((a, b) => a.service > b.service ? 1 : -1)
|
|
|
|
this.saveOrder()
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2022-07-28 13:16:05 +02:00
|
|
|
*/
|
|
|
|
sortDesc() {
|
|
|
|
this.accounts.sort((a, b) => a.service < b.service ? 1 : -1)
|
|
|
|
this.saveOrder()
|
|
|
|
},
|
2023-02-08 16:05:45 +01:00
|
|
|
|
|
|
|
/**
|
2023-04-24 08:10:13 +02:00
|
|
|
*
|
2023-02-08 16:05:45 +01:00
|
|
|
*/
|
|
|
|
keyListener : function(e) {
|
|
|
|
if (e.key === "f" && (e.ctrlKey || e.metaKey)) {
|
|
|
|
e.preventDefault();
|
|
|
|
const searchBox = document.getElementById('txtSearch');
|
|
|
|
if (searchBox != undefined) {
|
|
|
|
searchBox.focus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
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%);*/
|
|
|
|
}
|
2023-04-24 08:10:13 +02:00
|
|
|
</style>
|