diff --git a/resources/js/components/OneTimePassword.vue b/resources/js/components/OneTimePassword.vue deleted file mode 100644 index 443b75bb..00000000 --- a/resources/js/components/OneTimePassword.vue +++ /dev/null @@ -1,90 +0,0 @@ - - - \ No newline at end of file diff --git a/resources/js/components/TwofaccountShow.vue b/resources/js/components/TwofaccountShow.vue index 32d062dd..2876b9e2 100644 --- a/resources/js/components/TwofaccountShow.vue +++ b/resources/js/components/TwofaccountShow.vue @@ -5,7 +5,10 @@

{{ service }}

{{ account }}

- +

{{ totp }}

+ @@ -13,8 +16,81 @@ export default { data() { return { + totp : '', + timerID: null, + position: null, + AccountId : null } }, + props: ['twofaccountid', 'service', 'account', 'icon'], + + methods: { + getOTP: function () { + + axios.get('api/twofaccounts/' + this.AccountId + '/totp').then(response => { + 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() + } } \ No newline at end of file diff --git a/resources/js/views/Accounts.vue b/resources/js/views/Accounts.vue index c3a679e4..4e8983c2 100644 --- a/resources/js/views/Accounts.vue +++ b/resources/js/views/Accounts.vue @@ -44,8 +44,8 @@ :twofaccountid='twofaccount.id' :service='twofaccount.service' :icon='twofaccount.icon' - :account='twofaccount.account'> - + :account='twofaccount.account' + ref="TwofaccountShow" >