2019-06-28 01:16:51 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<p id="otp" title="refresh" class="is-size-1 has-text-white">{{ totp }}</p>
|
|
|
|
<ul class="dots">
|
2019-07-02 00:48:48 +02:00
|
|
|
<li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li>
|
2019-06-28 01:16:51 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
totp : '',
|
2019-07-02 00:48:48 +02:00
|
|
|
componentKey: 0,
|
|
|
|
timerID: null,
|
|
|
|
position: null,
|
|
|
|
AccountId : null
|
2019-06-28 01:16:51 +02:00
|
|
|
}
|
|
|
|
},
|
2020-01-10 23:30:38 +01:00
|
|
|
|
2019-06-28 01:16:51 +02:00
|
|
|
methods: {
|
|
|
|
getOTP: function () {
|
2019-07-02 00:48:48 +02:00
|
|
|
|
2019-06-28 01:16:51 +02:00
|
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
|
2019-07-02 00:48:48 +02:00
|
|
|
axios.get('api/twofaccounts/' + this.AccountId + '/totp').then(response => {
|
2020-01-10 23:30:38 +01:00
|
|
|
let spacePosition = Math.ceil(response.data.totp.length / 2);
|
|
|
|
|
|
|
|
this.totp = response.data.totp.substr(0, spacePosition) + " " + response.data.totp.substr(spacePosition);
|
2019-07-02 00:48:48 +02:00
|
|
|
this.position = response.data.position;
|
2019-06-28 01:16:51 +02:00
|
|
|
|
2019-07-02 00:48:48 +02:00
|
|
|
let dots = this.$el.querySelector('.dots');
|
2019-06-28 01:16:51 +02:00
|
|
|
|
2019-07-02 00:48:48 +02:00
|
|
|
// clear active dots
|
|
|
|
while (dots.querySelector('[data-is-active]')) {
|
|
|
|
dots.querySelector('[data-is-active]').removeAttribute('data-is-active');
|
2019-06-28 01:16:51 +02:00
|
|
|
}
|
2019-07-02 00:48:48 +02:00
|
|
|
|
|
|
|
// 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() {
|
|
|
|
|
2019-06-28 01:16:51 +02:00
|
|
|
let sibling = active.nextSibling;
|
|
|
|
|
2019-07-02 00:48:48 +02:00
|
|
|
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)
|
2019-06-28 01:16:51 +02:00
|
|
|
}
|
2019-07-02 00:48:48 +02:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
this.stopLoop()
|
2019-06-28 01:16:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|