2019-06-24 00:29:14 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div class="container">
|
|
|
|
<div class="buttons are-large is-centered">
|
2020-01-02 00:09:52 +01:00
|
|
|
<span v-for="account in accounts" class="button is-black twofaccount" >
|
|
|
|
<span @click.stop="getAccount(account.id)">
|
2020-01-05 23:21:28 +01:00
|
|
|
<img :src="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>
|
|
|
|
<a v-on:click="deleteAccount(account.id)">Delete</a>
|
2019-06-24 00:29:14 +02:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</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-06 21:45:14 +01:00
|
|
|
:account='twofaccount.account'>
|
2019-12-21 23:25:19 +01:00
|
|
|
<one-time-password ref="OneTimePassword"></one-time-password>
|
|
|
|
</twofaccount-show>
|
2019-06-24 00:29:14 +02:00
|
|
|
</modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
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
|
|
|
import OneTimePassword from '../components/OneTimePassword'
|
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
export default {
|
|
|
|
data(){
|
|
|
|
return {
|
|
|
|
accounts : [],
|
2019-12-21 23:25:19 +01:00
|
|
|
ShowTwofaccountInModal : false,
|
2019-06-24 00:29:14 +02:00
|
|
|
twofaccount: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted(){
|
|
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
|
|
|
|
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,
|
|
|
|
account : data.account,
|
2019-06-24 00:29:14 +02:00
|
|
|
icon : data.icon
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-07-02 00:48:48 +02:00
|
|
|
|
|
|
|
this.$on('modalClose', function() {
|
|
|
|
console.log('modalClose triggered')
|
|
|
|
this.$refs.OneTimePassword.clearOTP()
|
|
|
|
});
|
2019-12-21 23:25:19 +01:00
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
Modal,
|
2019-12-21 23:25:19 +01:00
|
|
|
TwofaccountShow,
|
2019-06-28 01:16:51 +02:00
|
|
|
OneTimePassword
|
2019-06-24 00:29:14 +02:00
|
|
|
},
|
|
|
|
methods: {
|
2019-06-28 01:16:51 +02:00
|
|
|
getAccount: function (id) {
|
2019-06-24 00:29:14 +02:00
|
|
|
let token = localStorage.getItem('jwt')
|
2019-06-28 01:16:51 +02:00
|
|
|
let accountId = id
|
2019-06-24 00:29:14 +02:00
|
|
|
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
|
|
|
|
axios.get('api/twofaccounts/' + id).then(response => {
|
2019-07-02 00:48:48 +02:00
|
|
|
|
2019-06-28 01:16:51 +02:00
|
|
|
this.twofaccount.id = response.data.id
|
2020-01-06 21:45:14 +01:00
|
|
|
this.twofaccount.service = response.data.service
|
|
|
|
this.twofaccount.account = response.data.account
|
2019-06-28 01:16:51 +02:00
|
|
|
this.twofaccount.icon = response.data.icon
|
2019-06-24 00:29:14 +02:00
|
|
|
|
2019-07-02 00:48:48 +02:00
|
|
|
this.$refs.OneTimePassword.AccountId = response.data.id
|
|
|
|
this.$refs.OneTimePassword.getOTP()
|
2019-12-21 23:25:19 +01:00
|
|
|
this.ShowTwofaccountInModal = true;
|
2019-06-24 00:29:14 +02:00
|
|
|
|
2019-06-28 01:16:51 +02:00
|
|
|
})
|
2020-01-02 00:09:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteAccount: function (id) {
|
2020-01-06 22:03:40 +01:00
|
|
|
if(confirm("Are you sure you want to delete this account?")) {
|
|
|
|
let token = localStorage.getItem('jwt')
|
2020-01-02 00:09:52 +01:00
|
|
|
|
2020-01-06 22:03:40 +01:00
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
2020-01-02 00:09:52 +01:00
|
|
|
|
2020-01-06 22:03:40 +01:00
|
|
|
axios.delete('/api/twofaccounts/' + id).then(response => {
|
|
|
|
this.accounts.splice(this.accounts.findIndex(x => x.id === id), 1);
|
|
|
|
})
|
|
|
|
}
|
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>
|
|
|
|
|