2019-06-24 00:29:14 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
2020-01-07 17:05:13 +01:00
|
|
|
<div class="container" v-if="this.accounts.length > 0">
|
2019-06-24 00:29:14 +02:00
|
|
|
<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>
|
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-07 21:45:47 +01:00
|
|
|
<div class="container has-text-centered" v-else>
|
|
|
|
<p>
|
|
|
|
<img class="bg" src="storage/bg.png">
|
|
|
|
</p>
|
|
|
|
<p class="subtitle is-5">
|
|
|
|
No 2FA here!
|
|
|
|
</p>
|
|
|
|
<router-link :to="{ name: 'create' }" class="button is-medium is-link is-focused">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-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>
|
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">
|
|
|
|
<a class="button is-dark is-rounded" @click="editMode = true" v-if="!editMode">Manage</a>
|
|
|
|
<div class="field has-addons" v-if="editMode">
|
|
|
|
<p class="control">
|
|
|
|
<button class="button is-success is-rounded" @click="editMode = false">
|
|
|
|
<span class="icon is-small">
|
|
|
|
<font-awesome-icon :icon="['fas', 'check']" />
|
|
|
|
</span>
|
|
|
|
<span>Done</span>
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
<p class="control">
|
|
|
|
<router-link :to="{ name: 'create' }" class="button is-dark is-rounded">
|
|
|
|
<span class="icon is-small">
|
2020-01-07 13:43:18 +01:00
|
|
|
<font-awesome-icon :icon="['fas', 'qrcode']" />
|
2020-01-07 11:46:18 +01:00
|
|
|
</span>
|
|
|
|
</router-link>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="content has-text-centered">
|
|
|
|
<span v-if="token">
|
|
|
|
Hi {{username}} ! <a class="" @click="logout">Sign out</a>
|
|
|
|
</span>
|
|
|
|
<span v-else>
|
|
|
|
<router-link :to="{ name: 'login' }" class="button is-black">
|
|
|
|
Sign in
|
|
|
|
</router-link>
|
|
|
|
<router-link :to="{ name: 'register' }" class="button is-black">
|
|
|
|
Register
|
|
|
|
</router-link>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</footer>
|
2019-06-24 00:29:14 +02:00
|
|
|
</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,
|
2020-01-06 23:11:18 +01:00
|
|
|
twofaccount: {},
|
2020-01-07 11:46:18 +01:00
|
|
|
token : null,
|
|
|
|
username : null,
|
2020-01-07 15:46:48 +01:00
|
|
|
editMode: this.InitialEditMode
|
2019-06-24 00:29:14 +02:00
|
|
|
}
|
|
|
|
},
|
2020-01-07 15:46:48 +01:00
|
|
|
|
|
|
|
props: ['InitialEditMode'],
|
|
|
|
|
2019-06-24 00:29:14 +02:00
|
|
|
mounted(){
|
2020-01-07 11:46:18 +01:00
|
|
|
this.token = localStorage.getItem('jwt')
|
|
|
|
this.username = localStorage.getItem('user')
|
2019-06-24 00:29:14 +02:00
|
|
|
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
2020-01-07 11:46:18 +01:00
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + this.token
|
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,
|
|
|
|
account : data.account,
|
2019-06-24 00:29:14 +02:00
|
|
|
icon : data.icon
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
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')
|
|
|
|
this.$refs.OneTimePassword.clearOTP()
|
|
|
|
});
|
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-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) {
|
|
|
|
let accountId = id
|
2019-06-24 00:29:14 +02:00
|
|
|
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
2020-01-07 11:46:18 +01:00
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + this.token
|
2019-06-24 00:29:14 +02:00
|
|
|
|
|
|
|
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?")) {
|
2020-01-02 00:09:52 +01:00
|
|
|
|
2020-01-06 22:03:40 +01:00
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
2020-01-07 11:46:18 +01:00
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + this.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);
|
|
|
|
})
|
|
|
|
}
|
2020-01-07 11:46:18 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
logout(evt) {
|
|
|
|
if(confirm("Are you sure you want to log out?")) {
|
|
|
|
axios.post('api/logout').then(response => {
|
|
|
|
|
|
|
|
localStorage.removeItem('jwt');
|
|
|
|
delete axios.defaults.headers.common['Authorization'];
|
|
|
|
|
|
|
|
this.$router.go('/login');
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
localStorage.removeItem('jwt');
|
|
|
|
delete axios.defaults.headers.common['Authorization'];
|
|
|
|
|
|
|
|
this.$router.go('/login');
|
|
|
|
});
|
|
|
|
}
|
2019-06-24 00:29:14 +02:00
|
|
|
}
|
2020-01-07 11:46:18 +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>
|
|
|
|
|