2019-12-21 23:23:44 +01:00
|
|
|
<template>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="section">
|
|
|
|
<div class="columns is-mobile is-centered">
|
|
|
|
<div class="column is-two-thirds-tablet is-half-desktop is-one-third-widescreen is-one-quarter-fullhd">
|
2020-01-12 19:55:17 +01:00
|
|
|
<h1 class="title">{{ $t('twofaccounts.forms.new_account') }}</h1>
|
2020-01-06 17:00:56 +01:00
|
|
|
<form @submit.prevent="createAccount">
|
|
|
|
<div class="field">
|
|
|
|
<div class="file is-dark is-boxed">
|
2020-01-12 19:55:17 +01:00
|
|
|
<label class="file-label" :title="$t('twofaccounts.forms.use_qrcode.title')">
|
2020-01-06 17:00:56 +01:00
|
|
|
<input class="file-input" type="file" accept="image/*" v-on:change="uploadQrcode" ref="qrcodeInput">
|
|
|
|
<span class="file-cta">
|
|
|
|
<span class="file-icon">
|
|
|
|
<font-awesome-icon :icon="['fas', 'qrcode']" size="lg" />
|
|
|
|
</span>
|
2020-01-12 19:55:17 +01:00
|
|
|
<span class="file-label">{{ $t('twofaccounts.forms.use_qrcode.val') }}</span>
|
2020-01-06 17:00:56 +01:00
|
|
|
</span>
|
|
|
|
</label>
|
2020-01-02 00:09:19 +01:00
|
|
|
</div>
|
2019-12-21 23:23:44 +01:00
|
|
|
</div>
|
2020-01-09 16:33:32 +01:00
|
|
|
<p class="help is-danger help-for-file" v-if="errors.qrcode">{{ errors.qrcode.toString() }}</p>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="field">
|
2020-01-12 19:55:17 +01:00
|
|
|
<label class="label">{{ $t('twofaccounts.service') }}</label>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="twofaccount.service" autofocus />
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
2020-01-09 16:33:32 +01:00
|
|
|
<p class="help is-danger" v-if="errors.service">{{ errors.service.toString() }}</p>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-01-12 19:55:17 +01:00
|
|
|
<label class="label">{{ $t('twofaccounts.account') }}</label>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="twofaccount.account" />
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
2020-01-09 16:33:32 +01:00
|
|
|
<p class="help is-danger" v-if="errors.account">{{ errors.account.toString() }}</p>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
2020-01-08 14:56:31 +01:00
|
|
|
<div class="field" style="margin-bottom: 0.5rem;">
|
2020-01-12 19:55:17 +01:00
|
|
|
<label class="label">{{ $t('twofaccounts.forms.totp_uri') }}</label>
|
2020-01-08 14:56:31 +01:00
|
|
|
</div>
|
|
|
|
<div class="field has-addons">
|
|
|
|
<div class="control is-expanded">
|
|
|
|
<input class="input" type="text" placeholder="otpauth://totp/..." v-model="twofaccount.uri" :disabled="uriIsLocked" />
|
|
|
|
</div>
|
|
|
|
<div class="control" v-if="uriIsLocked">
|
2020-01-12 19:55:17 +01:00
|
|
|
<a class="button is-dark field-lock" @click="uriIsLocked = false" :title="$t('twofaccounts.forms.unlock.title')">
|
2020-01-08 14:56:31 +01:00
|
|
|
<span class="icon">
|
|
|
|
<font-awesome-icon :icon="['fas', 'lock']" />
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class="control" v-else>
|
2020-01-12 19:55:17 +01:00
|
|
|
<a class="button is-dark field-unlock" @click="uriIsLocked = true" :title="$t('twofaccounts.forms.lock.title')">
|
2020-01-08 14:56:31 +01:00
|
|
|
<span class="icon has-text-danger">
|
|
|
|
<font-awesome-icon :icon="['fas', 'lock-open']" />
|
|
|
|
</span>
|
|
|
|
</a>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-09 16:33:32 +01:00
|
|
|
<p class="help is-danger help-for-file" v-if="errors.uri">{{ errors.uri.toString() }}</p>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="field">
|
2020-01-12 19:55:17 +01:00
|
|
|
<label class="label">{{ $t('twofaccounts.icon') }}</label>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="file is-dark">
|
|
|
|
<label class="file-label">
|
|
|
|
<input class="file-input" type="file" accept="image/*" v-on:change="uploadIcon" ref="iconInput">
|
|
|
|
<span class="file-cta">
|
|
|
|
<span class="file-icon">
|
|
|
|
<font-awesome-icon :icon="['fas', 'image']" />
|
|
|
|
</span>
|
2020-01-12 19:55:17 +01:00
|
|
|
<span class="file-label">{{ $t('twofaccounts.forms.choose_image') }}</span>
|
2020-01-06 17:00:56 +01:00
|
|
|
</span>
|
|
|
|
</label>
|
2020-01-08 23:22:51 +01:00
|
|
|
<span class="tag is-black is-large" v-if="tempIcon">
|
|
|
|
<img class="icon-preview" :src="'storage/icons/' + tempIcon" >
|
2020-01-08 17:10:56 +01:00
|
|
|
<button class="delete is-small" @click.prevent="deleteIcon"></button>
|
2020-01-08 14:56:31 +01:00
|
|
|
</span>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-09 16:33:32 +01:00
|
|
|
<p class="help is-danger help-for-file" v-if="errors.icon">{{ errors.icon.toString() }}</p>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="field is-grouped">
|
|
|
|
<div class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<button type="submit" class="button is-link">{{ $t('twofaccounts.forms.create') }}</button>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
<div class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<button class="button is-text" @click="cancelCreation">{{ $t('commons.cancel') }}</button>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2019-12-21 23:23:44 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2020-01-05 23:21:28 +01:00
|
|
|
twofaccount: {
|
2020-01-06 21:45:14 +01:00
|
|
|
'service' : '',
|
|
|
|
'account' : '',
|
2020-01-05 23:21:28 +01:00
|
|
|
'uri' : '',
|
|
|
|
'icon' : ''
|
2020-01-08 14:56:31 +01:00
|
|
|
},
|
2020-01-08 23:22:51 +01:00
|
|
|
uriIsLocked: true,
|
2020-01-09 16:33:32 +01:00
|
|
|
tempIcon: '',
|
|
|
|
errors: {}
|
2019-12-21 23:23:44 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
createAccount: function() {
|
2020-01-08 23:22:51 +01:00
|
|
|
// set current temp icon as account icon
|
|
|
|
this.twofaccount.icon = this.tempIcon
|
|
|
|
|
|
|
|
// store the account
|
2019-12-21 23:23:44 +01:00
|
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
|
2020-01-09 16:33:32 +01:00
|
|
|
axios.post('/api/twofaccounts', this.twofaccount)
|
|
|
|
.then(response => {
|
2020-01-07 23:10:04 +01:00
|
|
|
this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
|
2019-12-21 23:23:44 +01:00
|
|
|
})
|
2020-01-09 16:33:32 +01:00
|
|
|
.catch(error => {
|
|
|
|
if (error.response.status === 400) {
|
|
|
|
this.errors = error.response.data.error
|
|
|
|
}
|
|
|
|
});
|
2020-01-03 17:25:56 +01:00
|
|
|
},
|
|
|
|
|
2020-01-08 23:22:51 +01:00
|
|
|
cancelCreation: function() {
|
|
|
|
// clean possible uploaded temp icon
|
|
|
|
if( this.tempIcon ) {
|
|
|
|
this.deleteIcon()
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
|
|
|
|
},
|
|
|
|
|
2020-01-03 17:25:56 +01:00
|
|
|
uploadQrcode(event) {
|
|
|
|
|
|
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
|
|
|
|
let imgdata = new FormData();
|
|
|
|
|
2020-01-09 16:33:32 +01:00
|
|
|
imgdata.append('qrcode', this.$refs.qrcodeInput.files[0]);
|
2020-01-03 17:25:56 +01:00
|
|
|
|
|
|
|
let config = {
|
|
|
|
header : {
|
|
|
|
'Content-Type' : 'multipart/form-data',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 16:33:32 +01:00
|
|
|
axios.post('/api/qrcode/decode', imgdata, config)
|
|
|
|
.then(response => {
|
2020-01-03 17:25:56 +01:00
|
|
|
this.twofaccount = response.data;
|
2020-01-09 16:33:32 +01:00
|
|
|
this.errors['qrcode'] = '';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error.response.status === 400) {
|
|
|
|
this.errors = error.response.data.error
|
2020-01-09 20:33:31 +01:00
|
|
|
this.clearTwofaccount()
|
2020-01-09 16:33:32 +01:00
|
|
|
}
|
|
|
|
});
|
2020-01-05 23:21:28 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
uploadIcon(event) {
|
|
|
|
|
|
|
|
let token = localStorage.getItem('jwt')
|
|
|
|
|
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
|
|
|
|
2020-01-08 23:22:51 +01:00
|
|
|
// clean possible already uploaded temp icon
|
|
|
|
if( this.tempIcon ) {
|
2020-01-08 15:24:34 +01:00
|
|
|
this.deleteIcon()
|
2020-01-08 23:22:51 +01:00
|
|
|
}
|
2020-01-05 23:21:28 +01:00
|
|
|
|
|
|
|
let imgdata = new FormData();
|
|
|
|
|
2020-01-09 16:33:32 +01:00
|
|
|
imgdata.append('icon', this.$refs.iconInput.files[0]);
|
2020-01-05 23:21:28 +01:00
|
|
|
|
|
|
|
let config = {
|
|
|
|
header : {
|
|
|
|
'Content-Type' : 'multipart/form-data',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 16:33:32 +01:00
|
|
|
axios.post('/api/icon/upload', imgdata, config)
|
|
|
|
.then(response => {
|
2020-01-05 23:21:28 +01:00
|
|
|
console.log('icon path > ', response);
|
2020-01-08 23:22:51 +01:00
|
|
|
this.tempIcon = response.data;
|
2020-01-09 16:33:32 +01:00
|
|
|
this.errors['icon'] = '';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error.response.status === 400) {
|
|
|
|
this.errors = error.response.data.error
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-08 15:24:34 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteIcon(event) {
|
|
|
|
|
2020-01-09 20:33:31 +01:00
|
|
|
if(this.tempIcon) {
|
|
|
|
let token = localStorage.getItem('jwt')
|
2020-01-08 15:24:34 +01:00
|
|
|
|
2020-01-09 20:33:31 +01:00
|
|
|
axios.defaults.headers.common['Content-Type'] = 'application/json'
|
|
|
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
2020-01-08 15:24:34 +01:00
|
|
|
|
2020-01-09 20:33:31 +01:00
|
|
|
axios.delete('/api/icon/delete/' + this.tempIcon).then(response => {
|
|
|
|
this.tempIcon = ''
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearTwofaccount() {
|
|
|
|
this.twofaccount.service = ''
|
|
|
|
this.twofaccount.account = ''
|
|
|
|
this.twofaccount.uri = ''
|
|
|
|
this.twofaccount.icon = ''
|
|
|
|
|
|
|
|
this.deleteIcon()
|
2019-12-21 23:23:44 +01:00
|
|
|
}
|
2020-01-08 16:14:25 +01:00
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|