2019-12-21 23:25:19 +01:00
|
|
|
<template>
|
|
|
|
<div>
|
2020-01-08 17:03:41 +01:00
|
|
|
<figure class="image is-64x64" style="display: inline-block" v-if="icon">
|
2020-01-08 23:22:51 +01:00
|
|
|
<img :src="'storage/icons/' + icon">
|
2019-12-21 23:25:19 +01:00
|
|
|
</figure>
|
2020-01-06 21:45:14 +01:00
|
|
|
<p class="is-size-4 has-text-grey-light">{{ service }}</p>
|
|
|
|
<p class="is-size-6 has-text-grey">{{ account }}</p>
|
2020-01-22 15:27:33 +01:00
|
|
|
<p id="otp" class="is-size-1 has-text-white" :title="$t('commons.copy_to_clipboard')" v-clipboard="() => totp.replace(/ /g, '')" v-clipboard:success="clipboardSuccessHandler">{{ totp }}</p>
|
|
|
|
<ul class="dots">
|
|
|
|
<li v-for="n in 30"></li>
|
|
|
|
</ul>
|
2019-12-21 23:25:19 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2020-01-22 17:32:41 +01:00
|
|
|
service: '',
|
|
|
|
account: '',
|
|
|
|
icon: '',
|
2020-01-22 15:27:33 +01:00
|
|
|
totp : '',
|
|
|
|
timerID: null,
|
|
|
|
position: null,
|
2019-12-21 23:25:19 +01:00
|
|
|
}
|
|
|
|
},
|
2020-01-22 15:27:33 +01:00
|
|
|
|
2020-01-22 17:32:41 +01:00
|
|
|
props: ['twofaccountid'],
|
2020-01-22 15:27:33 +01:00
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
2020-01-22 17:32:41 +01:00
|
|
|
getAccount: function() {
|
|
|
|
|
|
|
|
axios.get('api/twofaccounts/' + this.twofaccountid)
|
|
|
|
.then(response => {
|
|
|
|
|
|
|
|
this.service = response.data.service
|
|
|
|
this.account = response.data.account
|
|
|
|
this.icon = response.data.icon
|
|
|
|
|
|
|
|
this.getOTP(this.twofaccountid)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getOTP: function(id) {
|
|
|
|
|
|
|
|
axios.get('api/twofaccounts/' + id + '/totp').then(response => {
|
2020-01-22 15:27:33 +01:00
|
|
|
let spacePosition = Math.ceil(response.data.totp.length / 2);
|
|
|
|
|
|
|
|
this.totp = response.data.totp.substr(0, spacePosition) + " " + response.data.totp.substr(spacePosition);
|
|
|
|
this.position = response.data.position;
|
|
|
|
|
|
|
|
let dots = this.$el.querySelector('.dots');
|
|
|
|
|
|
|
|
// clear active dots
|
|
|
|
while (dots.querySelector('[data-is-active]')) {
|
|
|
|
dots.querySelector('[data-is-active]').removeAttribute('data-is-active');
|
|
|
|
}
|
|
|
|
|
|
|
|
// set dot at given position as the active one
|
|
|
|
let active = dots.querySelector('li:nth-child(' + (this.position + 1 ) + ')');
|
|
|
|
active.setAttribute('data-is-active', true);
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
this.timerID = setInterval(function() {
|
|
|
|
|
|
|
|
let sibling = active.nextSibling;
|
|
|
|
|
|
|
|
if(active.nextSibling === null) {
|
|
|
|
console.log('no more sibling to activate, we refresh the TOTP')
|
|
|
|
self.stopLoop()
|
|
|
|
self.getOTP();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
active.removeAttribute('data-is-active');
|
|
|
|
sibling.setAttribute('data-is-active', true);
|
|
|
|
active = sibling
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 1000);
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
clearOTP: function() {
|
|
|
|
this.stopLoop()
|
|
|
|
this.timerID = null
|
|
|
|
this.totp = '... ...'
|
|
|
|
this.$el.querySelector('[data-is-active]').removeAttribute('data-is-active');
|
|
|
|
this.$el.querySelector('.dots li:first-child').setAttribute('data-is-active', true);
|
|
|
|
},
|
|
|
|
|
|
|
|
stopLoop: function() {
|
|
|
|
clearInterval(this.timerID)
|
|
|
|
},
|
|
|
|
|
|
|
|
clipboardSuccessHandler ({ value, event }) {
|
|
|
|
console.log('success', value)
|
|
|
|
},
|
|
|
|
|
|
|
|
clipboardErrorHandler ({ value, event }) {
|
|
|
|
console.log('error', value)
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeDestroy () {
|
|
|
|
this.stopLoop()
|
|
|
|
}
|
2019-12-21 23:25:19 +01:00
|
|
|
}
|
|
|
|
</script>
|