2019-12-21 23:23:44 +01:00
|
|
|
<template>
|
2020-01-10 00:07:37 +01:00
|
|
|
<div class="section" v-if="twofaccountExists">
|
2020-01-06 17:00:56 +01:00
|
|
|
<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.edit_account') }}</h1>
|
2020-01-20 22:51:57 +01:00
|
|
|
<form @submit.prevent="updateAccount" @keydown="form.onKeydown($event)">
|
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-20 22:51:57 +01:00
|
|
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="form.service" autofocus />
|
2020-01-02 00:09:19 +01:00
|
|
|
</div>
|
2020-01-20 22:51:57 +01:00
|
|
|
<field-error :form="form" field="service" />
|
2020-01-02 00:09:19 +01:00
|
|
|
</div>
|
2020-01-06 17:00:56 +01:00
|
|
|
<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-20 22:51:57 +01:00
|
|
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="form.account" />
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
2020-01-20 22:51:57 +01:00
|
|
|
<field-error :form="form" field="account" />
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
2020-01-25 18:40:32 +01:00
|
|
|
<div v-if="form.type === 'hotp'">
|
2020-01-24 12:56:38 +01:00
|
|
|
<div class="field" style="margin-bottom: 0.5rem;">
|
|
|
|
<label class="label">{{ $t('twofaccounts.forms.hotp_counter') }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="field has-addons">
|
|
|
|
<div class="control is-expanded">
|
|
|
|
<input class="input" type="text" placeholder="" v-model="form.counter" :disabled="counterIsLocked" />
|
|
|
|
</div>
|
|
|
|
<div class="control" v-if="counterIsLocked">
|
|
|
|
<a class="button is-dark field-lock" @click="counterIsLocked = false" :title="$t('twofaccounts.forms.unlock.title')">
|
|
|
|
<span class="icon">
|
|
|
|
<font-awesome-icon :icon="['fas', 'lock']" />
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class="control" v-else>
|
|
|
|
<a class="button is-dark field-unlock" @click="counterIsLocked = true" :title="$t('twofaccounts.forms.lock.title')">
|
|
|
|
<span class="icon has-text-danger">
|
|
|
|
<font-awesome-icon :icon="['fas', 'lock-open']" />
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<field-error :form="form" field="uri" class="help-for-file" />
|
|
|
|
</div>
|
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 16:14:25 +01:00
|
|
|
</span>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-20 22:51:57 +01:00
|
|
|
<field-error :form="form" field="icon" class="help-for-file" />
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="field is-grouped">
|
|
|
|
<div class="control">
|
2020-01-21 17:03:00 +01:00
|
|
|
<v-button :isLoading="form.isBusy" >{{ $t('twofaccounts.forms.save') }}</v-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.prevent="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>
|
2020-01-02 00:09:19 +01:00
|
|
|
</div>
|
2019-12-21 23:23:44 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-01-20 22:51:57 +01:00
|
|
|
|
|
|
|
import Form from './../../components/Form'
|
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2020-01-24 12:56:38 +01:00
|
|
|
counterIsLocked: true,
|
2020-01-10 00:07:37 +01:00
|
|
|
twofaccountExists: false,
|
2020-01-09 21:04:30 +01:00
|
|
|
tempIcon: '',
|
2020-01-20 22:51:57 +01:00
|
|
|
form: new Form({
|
|
|
|
service: '',
|
|
|
|
account: '',
|
|
|
|
uri: '',
|
|
|
|
icon: '',
|
2020-01-24 12:56:38 +01:00
|
|
|
qrcode: null,
|
|
|
|
type: '',
|
|
|
|
counter: null
|
2020-01-20 22:51:57 +01:00
|
|
|
})
|
2019-12-21 23:23:44 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-10 00:07:37 +01:00
|
|
|
created: function() {
|
2019-12-21 23:23:44 +01:00
|
|
|
this.getAccount();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-01-19 22:29:36 +01:00
|
|
|
getAccount () {
|
2020-01-16 22:21:05 +01:00
|
|
|
|
2020-01-19 22:29:36 +01:00
|
|
|
axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId)
|
|
|
|
.then(response => {
|
2020-01-20 22:51:57 +01:00
|
|
|
this.form.fill(response.data)
|
2020-01-10 00:07:37 +01:00
|
|
|
this.twofaccountExists = true
|
2020-01-08 23:22:51 +01:00
|
|
|
|
|
|
|
// set account icon as temp icon
|
2020-01-20 22:51:57 +01:00
|
|
|
this.tempIcon = this.form.icon
|
2020-01-19 22:29:36 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2020-01-17 00:23:38 +01:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
2020-01-19 22:29:36 +01:00
|
|
|
});
|
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
|
|
|
|
2020-01-19 22:29:36 +01:00
|
|
|
updateAccount() {
|
2020-01-08 23:22:51 +01:00
|
|
|
|
|
|
|
// Set new icon and delete old one
|
2020-01-20 22:51:57 +01:00
|
|
|
if( this.tempIcon !== this.form.icon ) {
|
2020-01-08 23:22:51 +01:00
|
|
|
let oldIcon = ''
|
|
|
|
|
2020-01-20 22:51:57 +01:00
|
|
|
oldIcon = this.form.icon
|
2020-01-08 23:22:51 +01:00
|
|
|
|
2020-01-20 22:51:57 +01:00
|
|
|
this.form.icon = this.tempIcon
|
2020-01-08 23:22:51 +01:00
|
|
|
this.tempIcon = oldIcon
|
|
|
|
this.deleteIcon()
|
|
|
|
}
|
|
|
|
|
2020-01-20 22:51:57 +01:00
|
|
|
this.form.put('/api/twofaccounts/' + this.$route.params.twofaccountId)
|
2020-01-19 22:29:36 +01:00
|
|
|
.then(response => {
|
2020-01-07 15:46:48 +01:00
|
|
|
this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
|
2020-01-19 22:29:36 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2020-01-20 22:51:57 +01:00
|
|
|
if( error.response.status !== 422 ) {
|
2020-01-21 08:43:11 +01:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
2020-01-14 12:23:31 +01:00
|
|
|
}
|
2020-01-19 22:29:36 +01:00
|
|
|
});
|
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
2020-01-05 23:21:28 +01:00
|
|
|
|
2020-01-08 23:22:51 +01:00
|
|
|
cancelCreation: function() {
|
|
|
|
// clean new temp icon
|
2020-01-16 22:21:05 +01:00
|
|
|
this.deleteIcon()
|
2020-01-08 23:22:51 +01:00
|
|
|
|
|
|
|
this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
|
|
|
|
},
|
|
|
|
|
2020-01-19 22:29:36 +01:00
|
|
|
uploadIcon(event) {
|
2020-01-05 23:21:28 +01:00
|
|
|
|
2020-01-08 23:22:51 +01:00
|
|
|
// clean possible tempIcon but keep original one
|
2020-01-16 22:21:05 +01:00
|
|
|
this.deleteIcon()
|
2020-01-05 23:21:28 +01:00
|
|
|
|
|
|
|
let imgdata = new FormData();
|
2020-01-20 22:51:57 +01:00
|
|
|
imgdata.append('icon', this.$refs.iconInput.files[0]);
|
2020-01-05 23:21:28 +01:00
|
|
|
|
2020-01-20 22:51:57 +01:00
|
|
|
this.form.upload('/api/icon/upload', imgdata)
|
2020-01-19 22:29:36 +01:00
|
|
|
.then(response => {
|
|
|
|
this.tempIcon = response.data;
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2020-01-20 22:51:57 +01:00
|
|
|
if( error.response.status !== 422 ) {
|
2020-01-21 08:43:11 +01:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
2020-01-16 22:21:05 +01:00
|
|
|
}
|
2020-01-19 22:29:36 +01:00
|
|
|
});
|
2020-01-16 22:21:05 +01:00
|
|
|
|
2020-01-08 16:14:25 +01:00
|
|
|
},
|
|
|
|
|
2020-01-19 22:29:36 +01:00
|
|
|
deleteIcon(event) {
|
2020-01-08 16:14:25 +01:00
|
|
|
|
2020-01-20 22:51:57 +01:00
|
|
|
if( this.tempIcon && this.tempIcon !== this.form.icon ) {
|
2020-01-19 22:29:36 +01:00
|
|
|
axios.delete('/api/icon/delete/' + this.tempIcon)
|
2020-01-08 23:22:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.tempIcon = ''
|
|
|
|
},
|
2020-01-08 16:14:25 +01:00
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|