2019-06-24 00:29:14 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
2020-01-08 00:39:20 +01:00
|
|
|
<div class="container" v-if="this.showAccounts">
|
2020-01-11 16:46:59 +01: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">
|
|
|
|
<div class="field">
|
|
|
|
<div class="control has-icons-right">
|
2020-01-12 19:55:17 +01:00
|
|
|
<input type="text" class="input is-rounded is-search" v-model="search">
|
2020-01-11 16:46:59 +01:00
|
|
|
<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>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-06-24 00:29:14 +02:00
|
|
|
<div class="buttons are-large is-centered">
|
2020-01-11 16:46:59 +01:00
|
|
|
<span v-for="account in filteredAccounts" class="button is-black has-background-black-bis twofaccount" >
|
2020-01-02 00:09:52 +01:00
|
|
|
<span @click.stop="getAccount(account.id)">
|
2020-01-08 23:22:51 +01:00
|
|
|
<img :src="'storage/icons/' + account.icon" v-if="account.icon">
|
2020-01-06 21:45:14 +01:00
|
|
|
{{ account.service }}
|
|
|
|
<span class="is-family-primary is-size-7 has-text-grey">{{ account.account }}</span>
|
2020-01-02 00:09:52 +01:00
|
|
|
</span>
|
2020-01-06 23:11:18 +01:00
|
|
|
<span v-if="editMode">
|
2020-01-07 11:46:18 +01:00
|
|
|
<router-link :to="{ name: 'edit', params: { twofaccountId: account.id }}" class="tag is-dark">
|
2020-01-06 23:11:18 +01:00
|
|
|
<font-awesome-icon :icon="['fas', 'edit']" />
|
|
|
|
</router-link>
|
2020-01-07 11:46:18 +01:00
|
|
|
<a class="tag is-dark" v-on:click="deleteAccount(account.id)">
|
|
|
|
<font-awesome-icon :icon="['fas', 'trash']" />
|
|
|
|
</a>
|
2020-01-06 23:11:18 +01:00
|
|
|
</span>
|
2019-06-24 00:29:14 +02:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-08 00:39:20 +01:00
|
|
|
<div class="container has-text-centered" v-show="this.showNoAccount">
|
2020-01-09 09:23:54 +01:00
|
|
|
<p class="no-account"></p>
|
2020-01-10 10:48:16 +01:00
|
|
|
<p class="subtitle is-5 has-text-grey">
|
2020-01-12 19:55:17 +01:00
|
|
|
{{ $t('twofaccounts.no_account_here') }}
|
2020-01-07 21:45:47 +01:00
|
|
|
</p>
|
2020-01-12 19:55:17 +01:00
|
|
|
<router-link :to="{ name: 'create' }" class="button is-medium is-link is-focused">{{ $t('twofaccounts.add_one') }}</router-link>
|
2020-01-07 17:05:13 +01:00
|
|
|
</div>
|
2019-12-21 23:25:19 +01:00
|
|
|
<modal v-model="ShowTwofaccountInModal">
|
|
|
|
<twofaccount-show
|
|
|
|
:twofaccountid='twofaccount.id'
|
2020-01-06 21:45:14 +01:00
|
|
|
:service='twofaccount.service'
|
2019-06-28 01:16:51 +02:00
|
|
|
:icon='twofaccount.icon'
|
2020-01-22 15:27:33 +01:00
|
|
|
:account='twofaccount.account'
|
|
|
|
ref="TwofaccountShow" >
|
2019-12-21 23:25:19 +01:00
|
|
|
</twofaccount-show>
|
2019-06-24 00:29:14 +02:00
|
|
|
</modal>
|
2020-01-07 11:46:18 +01:00
|
|
|
<footer class="has-background-black-ter">
|
2020-01-07 21:45:47 +01:00
|
|
|
<div class="columns is-gapless" v-if="this.accounts.length > 0">
|
2020-01-07 11:46:18 +01:00
|
|
|
<div class="column has-text-centered">
|
2020-01-07 23:10:04 +01:00
|
|
|
<div class="field is-grouped">
|
2020-01-07 11:46:18 +01:00
|
|
|
<p class="control">
|
2020-01-07 23:10:04 +01:00
|
|
|
<router-link :to="{ name: 'create' }" class="button is-link is-rounded is-focus">
|
2020-01-12 19:55:17 +01:00
|
|
|
<span>{{ $t('twofaccounts.new') }}</span>
|
2020-01-07 11:46:18 +01:00
|
|
|
<span class="icon is-small">
|
2020-01-07 23:10:04 +01:00
|
|
|
<font-awesome-icon :icon="['fas', 'qrcode']" />
|
2020-01-07 11:46:18 +01:00
|
|
|
</span>
|
2020-01-07 23:10:04 +01:00
|
|
|
</router-link>
|
2020-01-07 11:46:18 +01:00
|
|
|
</p>
|
|
|
|
<p class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<a class="button is-dark is-rounded" @click="editMode = true" v-if="!editMode">{{ $t('twofaccounts.manage') }}</a>
|
2020-01-07 23:10:04 +01:00
|
|
|
<a class="button is-success is-rounded" @click="editMode = false" v-if="editMode">
|
2020-01-12 19:55:17 +01:00
|
|
|
<span>{{ $t('twofaccounts.done') }}</span>
|
2020-01-07 11:46:18 +01:00
|
|
|
<span class="icon is-small">
|
2020-01-07 23:10:04 +01:00
|
|
|
<font-awesome-icon :icon="['fas', 'check']" />
|
2020-01-07 11:46:18 +01:00
|
|
|
</span>
|
2020-01-07 23:10:04 +01:00
|
|
|
</a>
|
2020-01-07 11:46:18 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="content has-text-centered">
|
2020-01-15 23:00:06 +01:00
|
|
|
{{ $t('auth.hello', {username: username}) }} <a class="has-text-grey" @click="logout">{{ $t('auth.sign_out') }}</a>
|
2020-01-07 11:46:18 +01:00
|
|
|
</div>
|
|
|
|
</footer>
|
2019-06-24 00:29:14 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-01-19 22:31:23 +01:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
import Modal from '../components/Modal'
|
2019-12-21 23:25:19 +01:00
|
|
|
import TwofaccountShow from '../components/TwofaccountShow'
|
2019-06-28 01:16:51 +02:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
export default {
|
|
|
|
data(){
|
|
|
|
return {
|
|
|
|
accounts : [],
|
2019-12-21 23:25:19 +01:00
|
|
|
ShowTwofaccountInModal : false,
|
2020-01-06 23:11:18 +01:00
|
|
|
twofaccount: {},
|
2020-01-11 16:46:59 +01:00
|
|
|
search: '',
|
2020-01-07 11:46:18 +01:00
|
|
|
token : null,
|
|
|
|
username : null,
|
2020-01-08 00:39:20 +01:00
|
|
|
editMode: this.InitialEditMode,
|
|
|
|
showAccounts: null,
|
|
|
|
showNoAccount: null
|
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: {
|
|
|
|
filteredAccounts() {
|
|
|
|
return this.accounts.filter(
|
|
|
|
item => {
|
|
|
|
return item.service.toLowerCase().includes(this.search.toLowerCase()) || item.account.toLowerCase().includes(this.search.toLowerCase());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2020-01-07 15:46:48 +01:00
|
|
|
props: ['InitialEditMode'],
|
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
mounted(){
|
|
|
|
|
2020-01-15 23:00:06 +01:00
|
|
|
this.username = localStorage.getItem('user')
|
2019-06-24 00:29:14 +02:00
|
|
|
|
|
|
|
axios.get('api/twofaccounts').then(response => {
|
|
|
|
response.data.forEach((data) => {
|
|
|
|
this.accounts.push({
|
|
|
|
id : data.id,
|
2020-01-06 21:45:14 +01:00
|
|
|
service : data.service,
|
2020-01-07 21:46:16 +01:00
|
|
|
account : data.account ? data.account : '-',
|
2019-06-24 00:29:14 +02:00
|
|
|
icon : data.icon
|
|
|
|
})
|
|
|
|
})
|
2020-01-19 22:31:23 +01:00
|
|
|
|
2020-01-08 00:39:20 +01:00
|
|
|
this.showAccounts = this.accounts.length > 0 ? true : false
|
|
|
|
this.showNoAccount = !this.showAccounts
|
2019-06-24 00:29:14 +02:00
|
|
|
})
|
2019-07-02 00:48:48 +02:00
|
|
|
|
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')
|
2020-01-22 15:27:33 +01:00
|
|
|
this.$refs.TwofaccountShow.clearOTP()
|
2020-01-09 22:11:11 +01:00
|
|
|
|
|
|
|
this.twofaccount.id = ''
|
|
|
|
this.twofaccount.service = ''
|
|
|
|
this.twofaccount.account = ''
|
|
|
|
this.twofaccount.icon = ''
|
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,
|
2019-12-21 23:25:19 +01:00
|
|
|
TwofaccountShow,
|
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-22 15:27:33 +01:00
|
|
|
async getAccount(id) {
|
|
|
|
|
|
|
|
const { data } = await axios.get('api/twofaccounts/' + id)
|
2020-01-19 22:29:36 +01:00
|
|
|
.catch(error => {
|
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
|
|
});
|
|
|
|
|
2020-01-22 15:27:33 +01:00
|
|
|
this.twofaccount.id = data.id
|
|
|
|
this.twofaccount.service = data.service
|
|
|
|
this.twofaccount.account = data.account
|
|
|
|
this.twofaccount.icon = data.icon
|
|
|
|
|
|
|
|
this.$refs.TwofaccountShow.AccountId = data.id
|
|
|
|
await this.$refs.TwofaccountShow.getOTP()
|
|
|
|
|
|
|
|
this.ShowTwofaccountInModal = true
|
|
|
|
|
2020-01-02 00:09:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteAccount: function (id) {
|
2020-01-12 19:55:17 +01:00
|
|
|
if(confirm(this.$t('twofaccounts.confirm.delete'))) {
|
2020-01-02 00:09:52 +01:00
|
|
|
|
2020-01-10 00:22:45 +01:00
|
|
|
axios.delete('/api/twofaccounts/' + id)
|
2020-01-08 00:39:20 +01:00
|
|
|
|
2020-01-10 00:22:45 +01:00
|
|
|
this.accounts.splice(this.accounts.findIndex(x => x.id === id), 1);
|
|
|
|
this.showAccounts = this.accounts.length > 0 ? true : false
|
|
|
|
this.showNoAccount = !this.showAccounts
|
2020-01-06 22:03:40 +01:00
|
|
|
}
|
2020-01-07 11:46:18 +01:00
|
|
|
},
|
|
|
|
|
2020-01-19 22:29:36 +01:00
|
|
|
logout(evt) {
|
2020-01-12 19:55:17 +01:00
|
|
|
if(confirm(this.$t('auth.confirm.logout'))) {
|
2020-01-07 11:46:18 +01:00
|
|
|
|
2020-01-19 22:29:36 +01:00
|
|
|
axios.get('api/logout')
|
|
|
|
.then(response => {
|
2020-01-07 11:46:18 +01:00
|
|
|
localStorage.removeItem('jwt');
|
2020-01-10 13:54:58 +01:00
|
|
|
localStorage.removeItem('user');
|
2020-01-16 17:12:25 +01:00
|
|
|
|
2020-01-07 11:46:18 +01:00
|
|
|
delete axios.defaults.headers.common['Authorization'];
|
|
|
|
|
|
|
|
this.$router.go('/login');
|
2020-01-19 22:29:36 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2020-01-17 00:23:38 +01:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
2020-01-19 22:29:36 +01:00
|
|
|
});
|
|
|
|
|
2020-01-07 11:46:18 +01:00
|
|
|
}
|
2019-06-24 00:29:14 +02:00
|
|
|
}
|
2020-01-07 11:46:18 +01:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
},
|
2020-01-08 00:39:20 +01:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
beforeRouteEnter (to, from, next) {
|
|
|
|
if ( ! localStorage.getItem('jwt')) {
|
|
|
|
return next('login')
|
|
|
|
}
|
|
|
|
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 01:16:51 +02:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
</script>
|
|
|
|
|