2019-12-21 23:23:44 +01:00
|
|
|
<template>
|
2020-01-28 15:33:33 +01:00
|
|
|
<form-wrapper :title="$t('twofaccounts.forms.edit_account')">
|
|
|
|
<form @submit.prevent="updateAccount" @keydown="form.onKeydown($event)">
|
2020-11-16 14:45:24 +01:00
|
|
|
<!-- service -->
|
2020-02-13 12:55:00 +01:00
|
|
|
<form-field :form="form" fieldName="service" inputType="text" :label="$t('twofaccounts.service')" :placeholder="$t('twofaccounts.forms.service.placeholder')" autofocus />
|
2020-11-16 14:45:24 +01:00
|
|
|
<!-- account -->
|
2020-02-13 12:55:00 +01:00
|
|
|
<form-field :form="form" fieldName="account" inputType="text" :label="$t('twofaccounts.account')" :placeholder="$t('twofaccounts.forms.account.placeholder')" />
|
2020-11-16 14:45:24 +01:00
|
|
|
<!-- icon -->
|
2020-01-28 15:33:33 +01:00
|
|
|
<div class="field">
|
|
|
|
<label class="label">{{ $t('twofaccounts.icon') }}</label>
|
|
|
|
<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>
|
|
|
|
<span class="file-label">{{ $t('twofaccounts.forms.choose_image') }}</span>
|
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
<span class="tag is-black is-large" v-if="tempIcon">
|
2020-01-29 14:56:13 +01:00
|
|
|
<img class="icon-preview" :src="'/storage/icons/' + tempIcon" >
|
2020-01-28 15:33:33 +01:00
|
|
|
<button class="delete is-small" @click.prevent="deleteIcon"></button>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<field-error :form="form" field="icon" class="help-for-file" />
|
2020-11-16 14:45:24 +01:00
|
|
|
<!-- otp type -->
|
2021-10-09 19:23:24 +02:00
|
|
|
<form-toggle class="has-uppercased-button" :isDisabled="true" :form="form" :choices="otp_types" fieldName="otp_type" :label="$t('twofaccounts.forms.otp_type.label')" :help="$t('twofaccounts.forms.otp_type.help')" :hasOffset="true" />
|
|
|
|
<div v-if="form.otp_type">
|
2020-11-16 14:45:24 +01:00
|
|
|
<!-- secret -->
|
|
|
|
<label class="label" v-html="$t('twofaccounts.forms.secret.label')"></label>
|
|
|
|
<div class="field has-addons">
|
|
|
|
<p class="control">
|
|
|
|
<span class="select">
|
|
|
|
<select v-model="form.secretIsBase32Encoded">
|
|
|
|
<option v-for="format in secretFormats" :value="format.value">{{ format.text }}</option>
|
|
|
|
</select>
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
<p class="control is-expanded">
|
|
|
|
<input class="input" type="text" v-model="form.secret">
|
|
|
|
</p>
|
2020-01-28 15:33:33 +01:00
|
|
|
</div>
|
2020-11-16 14:45:24 +01:00
|
|
|
<div class="field">
|
|
|
|
<field-error :form="form" field="secret" class="help-for-file" />
|
|
|
|
<p class="help" v-html="$t('twofaccounts.forms.secret.help')"></p>
|
2020-01-28 15:33:33 +01:00
|
|
|
</div>
|
2020-11-16 14:45:24 +01:00
|
|
|
<h2 class="title is-4 mt-5 mb-2">{{ $t('commons.options') }}</h2>
|
|
|
|
<p class="help mb-4">
|
|
|
|
{{ $t('twofaccounts.forms.options_help') }}
|
|
|
|
</p>
|
|
|
|
<!-- digits -->
|
|
|
|
<form-toggle :form="form" :choices="digitsChoices" fieldName="digits" :label="$t('twofaccounts.forms.digits.label')" :help="$t('twofaccounts.forms.digits.help')" />
|
|
|
|
<!-- algorithm -->
|
|
|
|
<form-toggle :form="form" :choices="algorithms" fieldName="algorithm" :label="$t('twofaccounts.forms.algorithm.label')" :help="$t('twofaccounts.forms.algorithm.help')" />
|
|
|
|
<!-- TOTP period -->
|
2021-10-09 19:23:24 +02:00
|
|
|
<form-field v-if="form.otp_type === 'totp'" :form="form" fieldName="period" inputType="text" :label="$t('twofaccounts.forms.period.label')" :placeholder="$t('twofaccounts.forms.period.placeholder')" :help="$t('twofaccounts.forms.period.help')" />
|
2020-11-16 14:45:24 +01:00
|
|
|
<!-- HOTP counter -->
|
2021-10-09 19:23:24 +02:00
|
|
|
<div v-if="form.otp_type === 'hotp'">
|
2020-11-16 14:45:24 +01:00
|
|
|
<div class="field" style="margin-bottom: 0.5rem;">
|
2021-10-09 19:23:24 +02:00
|
|
|
<label class="label">{{ $t('twofaccounts.forms.counter.label') }}</label>
|
2020-11-16 14:45:24 +01:00
|
|
|
</div>
|
|
|
|
<div class="field has-addons">
|
|
|
|
<div class="control is-expanded">
|
2021-10-09 19:23:24 +02:00
|
|
|
<input class="input" type="text" placeholder="" v-model="form.counter" :disabled="counterIsLocked" />
|
2020-11-16 14:45:24 +01:00
|
|
|
</div>
|
2021-10-09 19:23:24 +02:00
|
|
|
<div class="control" v-if="counterIsLocked">
|
|
|
|
<a class="button is-dark field-lock" @click="counterIsLocked = false" :title="$t('twofaccounts.forms.unlock.title')">
|
2020-11-16 14:45:24 +01:00
|
|
|
<span class="icon">
|
|
|
|
<font-awesome-icon :icon="['fas', 'lock']" />
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class="control" v-else>
|
2021-10-09 19:23:24 +02:00
|
|
|
<a class="button is-dark field-unlock" @click="counterIsLocked = true" :title="$t('twofaccounts.forms.lock.title')">
|
2020-11-16 14:45:24 +01:00
|
|
|
<span class="icon has-text-danger">
|
|
|
|
<font-awesome-icon :icon="['fas', 'lock-open']" />
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-09 19:23:24 +02:00
|
|
|
<field-error :form="form" field="counter" />
|
|
|
|
<p class="help" v-html="$t('twofaccounts.forms.counter.help_lock')"></p>
|
2020-11-16 14:45:24 +01:00
|
|
|
</div>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
2020-11-16 14:45:24 +01:00
|
|
|
<!-- form buttons -->
|
|
|
|
<vue-footer :showButtons="true">
|
|
|
|
<p class="control">
|
|
|
|
<v-button :isLoading="form.isBusy" class="is-rounded" >{{ $t('commons.save') }}</v-button>
|
|
|
|
</p>
|
2021-10-09 19:23:24 +02:00
|
|
|
<p class="control" v-if="form.otp_type && form.secret">
|
2020-11-16 14:45:24 +01:00
|
|
|
<button type="button" class="button is-success is-rounded" @click="previewAccount">{{ $t('twofaccounts.forms.test') }}</button>
|
|
|
|
</p>
|
|
|
|
<p class="control">
|
|
|
|
<button type="button" class="button is-text is-rounded" @click="cancelCreation">{{ $t('commons.cancel') }}</button>
|
|
|
|
</p>
|
|
|
|
</vue-footer>
|
2020-01-28 15:33:33 +01:00
|
|
|
</form>
|
2020-11-16 14:45:24 +01:00
|
|
|
<!-- modal -->
|
|
|
|
<modal v-model="ShowTwofaccountInModal">
|
2021-10-09 19:23:24 +02:00
|
|
|
<otp-displayer ref="AdvancedFormOtpDisplayer" v-bind="form.data()" @increment-hotp="incrementHotp">
|
|
|
|
</otp-displayer>
|
2020-11-16 14:45:24 +01:00
|
|
|
</modal>
|
2020-01-28 15:33:33 +01:00
|
|
|
</form-wrapper>
|
2019-12-21 23:23:44 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-01-20 22:51:57 +01:00
|
|
|
|
2020-11-16 14:45:24 +01:00
|
|
|
import Modal from '../../components/Modal'
|
2020-01-20 22:51:57 +01:00
|
|
|
import Form from './../../components/Form'
|
2021-10-09 19:23:24 +02:00
|
|
|
import OtpDisplayer from '../../components/OtpDisplayer'
|
2020-01-20 22:51:57 +01:00
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2020-11-16 14:45:24 +01:00
|
|
|
ShowTwofaccountInModal : false,
|
2021-10-09 19:23:24 +02: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: '',
|
2021-10-09 19:23:24 +02:00
|
|
|
otp_type: '',
|
2020-01-20 22:51:57 +01:00
|
|
|
uri: '',
|
|
|
|
icon: '',
|
2020-11-16 14:45:24 +01:00
|
|
|
secret: '',
|
|
|
|
secretIsBase32Encoded: null,
|
|
|
|
algorithm: '',
|
|
|
|
digits: null,
|
2021-10-09 19:23:24 +02:00
|
|
|
counter: null,
|
|
|
|
period: null,
|
|
|
|
image: '',
|
2020-11-16 14:45:24 +01:00
|
|
|
}),
|
2021-10-09 19:23:24 +02:00
|
|
|
otp_types: [
|
2020-11-19 14:07:31 +01:00
|
|
|
{ text: 'TOTP', value: 'totp' },
|
|
|
|
{ text: 'HOTP', value: 'hotp' },
|
|
|
|
],
|
|
|
|
digitsChoices: [
|
|
|
|
{ text: 6, value: 6 },
|
|
|
|
{ text: 7, value: 7 },
|
|
|
|
{ text: 8, value: 8 },
|
|
|
|
{ text: 9, value: 9 },
|
|
|
|
{ text: 10, value: 10 },
|
|
|
|
],
|
2020-11-16 14:45:24 +01:00
|
|
|
secretFormats: [
|
|
|
|
{ text: this.$t('twofaccounts.forms.plain_text'), value: 0 },
|
|
|
|
{ text: 'Base32', value: 1 }
|
|
|
|
],
|
2020-11-19 14:07:31 +01:00
|
|
|
algorithms: [
|
|
|
|
{ text: 'sha1', value: 'sha1' },
|
|
|
|
{ text: 'sha256', value: 'sha256' },
|
|
|
|
{ text: 'sha512', value: 'sha512' },
|
|
|
|
{ text: 'md5', value: 'md5' },
|
|
|
|
],
|
2019-12-21 23:23:44 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-11-16 14:45:24 +01:00
|
|
|
mounted: function () {
|
|
|
|
|
|
|
|
// stop TOTP generation on modal close
|
|
|
|
this.$on('modalClose', function() {
|
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
this.$refs.AdvancedFormOtpDisplayer.stopLoop()
|
2020-11-16 14:45:24 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-10 00:07:37 +01:00
|
|
|
created: function() {
|
2019-12-21 23:23:44 +01:00
|
|
|
this.getAccount();
|
|
|
|
},
|
|
|
|
|
2020-11-16 14:45:24 +01:00
|
|
|
components: {
|
|
|
|
Modal,
|
2021-10-09 19:23:24 +02:00
|
|
|
OtpDisplayer,
|
2020-11-16 14:45:24 +01:00
|
|
|
},
|
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
methods: {
|
2020-01-26 21:57:53 +01:00
|
|
|
async getAccount () {
|
2020-01-16 22:21:05 +01:00
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
const { data } = await this.axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId)
|
2020-01-08 23:22:51 +01:00
|
|
|
|
2020-01-26 21:57:53 +01:00
|
|
|
this.form.fill(data)
|
2020-11-16 14:45:24 +01:00
|
|
|
this.form.secretIsBase32Encoded = 1
|
2020-01-26 21:57:53 +01:00
|
|
|
this.twofaccountExists = true
|
2020-01-19 22:29:36 +01:00
|
|
|
|
2020-01-26 21:57:53 +01:00
|
|
|
// set account icon as temp icon
|
|
|
|
this.tempIcon = this.form.icon
|
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
|
|
|
|
2020-01-26 21:57:53 +01:00
|
|
|
async 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-27 14:55:30 +01:00
|
|
|
await this.form.put('/api/twofaccounts/' + this.$route.params.twofaccountId)
|
|
|
|
|
|
|
|
if( this.form.errors.any() === false ) {
|
2020-11-26 20:41:02 +01:00
|
|
|
this.$router.push({name: 'accounts', params: { InitialEditMode: true, toRefresh: true }})
|
2020-01-27 14:55:30 +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-11-16 14:45:24 +01:00
|
|
|
previewAccount() {
|
2021-10-09 19:23:24 +02:00
|
|
|
this.$refs.AdvancedFormOtpDisplayer.show()
|
2020-11-16 14:45:24 +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-27 14:55:30 +01:00
|
|
|
async 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
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
const { data } = await this.form.upload('/api/icons', imgdata)
|
2020-01-27 14:55:30 +01:00
|
|
|
|
|
|
|
this.tempIcon = data;
|
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 ) {
|
2021-10-09 19:23:24 +02:00
|
|
|
this.axios.delete('/api/icons/' + this.tempIcon)
|
2020-01-08 23:22:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.tempIcon = ''
|
|
|
|
},
|
2020-01-08 16:14:25 +01:00
|
|
|
|
2020-11-16 14:45:24 +01:00
|
|
|
incrementHotp(payload) {
|
|
|
|
// The quick form or the preview feature has incremented the HOTP counter so we get the new value from
|
|
|
|
// the component.
|
|
|
|
// This could desynchronized the HOTP verification server and our local counter if the user never verified the HOTP but this
|
|
|
|
// is acceptable (and HOTP counter can be edited by the way)
|
2021-10-09 19:23:24 +02:00
|
|
|
this.form.counter = payload.nextHotpCounter
|
2020-11-16 14:45:24 +01:00
|
|
|
this.form.uri = payload.nextUri
|
|
|
|
},
|
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|