paricafe/src/client/app/desktop/views/components/settings.2fa.vue

77 lines
2 KiB
Vue
Raw Normal View History

2018-02-12 08:48:01 -06:00
<template>
2018-02-21 10:25:57 -06:00
<div class="2fa">
<p style="margin-top:0;">{{ $t('intro') }}<a :href="$t('href')" target="_blank">{{ $t('detail') }}</a></p>
<ui-info warn>{{ $t('caution') }}</ui-info>
<p v-if="!data && !$store.state.i.twoFactorEnabled"><ui-button @click="register">{{ $t('register') }}</ui-button></p>
2018-05-26 23:49:09 -05:00
<template v-if="$store.state.i.twoFactorEnabled">
<p>{{ $t('already-registered') }}</p>
<ui-button @click="unregister">{{ $t('unregister') }}</ui-button>
2018-02-12 08:48:01 -06:00
</template>
<div v-if="data">
<ol>
<li>{{ $t('authenticator% <a href="https://support.google.com/accounts/answer/1066447" target="_blank">%i18n:@howtoinstall') }}</a></li>
<li>{{ $t('scan') }}<br><img :src="data.qr"></li>
<li>{{ $t('done') }}<br>
2018-02-12 08:48:01 -06:00
<input type="number" v-model="token" class="ui">
<ui-button primary @click="submit">{{ $t('submit') }}</ui-button>
2018-02-12 08:48:01 -06:00
</li>
</ol>
<div class="ui info"><p><fa icon="info-circle"/>{{ $t('info') }}</p></div>
2018-02-12 08:48:01 -06:00
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
2018-02-12 08:48:01 -06:00
export default Vue.extend({
i18n: i18n('desktop/views/components/settings.2fa.vue'),
2018-02-12 08:48:01 -06:00
data() {
return {
data: null,
token: null
};
},
methods: {
register() {
2018-02-21 10:25:57 -06:00
(this as any).apis.input({
title: this.$t('enter-password'),
2018-02-21 10:25:57 -06:00
type: 'password'
}).then(password => {
2018-02-17 21:35:18 -06:00
(this as any).api('i/2fa/register', {
2018-02-12 08:48:01 -06:00
password: password
}).then(data => {
this.data = data;
});
});
},
unregister() {
2018-02-21 10:25:57 -06:00
(this as any).apis.input({
title: this.$t('enter-password'),
2018-02-21 10:25:57 -06:00
type: 'password'
}).then(password => {
2018-02-17 21:35:18 -06:00
(this as any).api('i/2fa/unregister', {
2018-02-12 08:48:01 -06:00
password: password
}).then(() => {
(this as any).apis.notify(this.$t('unregistered'));
2018-05-26 23:49:09 -05:00
this.$store.state.i.twoFactorEnabled = false;
2018-02-12 08:48:01 -06:00
});
});
},
submit() {
2018-02-17 21:35:18 -06:00
(this as any).api('i/2fa/done', {
2018-02-12 08:48:01 -06:00
token: this.token
}).then(() => {
(this as any).apis.notify(this.$t('success'));
2018-05-26 23:49:09 -05:00
this.$store.state.i.twoFactorEnabled = true;
2018-02-12 08:48:01 -06:00
}).catch(() => {
(this as any).apis.notify(this.$t('failed'));
2018-02-12 08:48:01 -06:00
});
}
}
});
</script>