2018-02-12 23:48:01 +09:00
|
|
|
<template>
|
2018-02-22 01:25:57 +09:00
|
|
|
<div class="2fa">
|
2018-12-12 10:07:30 +09:00
|
|
|
<p style="margin-top:0;">{{ $t('intro') }}<a :href="$t('url')" target="_blank">{{ $t('detail') }}</a></p>
|
2018-11-09 03:44:35 +09:00
|
|
|
<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-27 13:49:09 +09:00
|
|
|
<template v-if="$store.state.i.twoFactorEnabled">
|
2018-11-09 03:44:35 +09:00
|
|
|
<p>{{ $t('already-registered') }}</p>
|
|
|
|
<ui-button @click="unregister">{{ $t('unregister') }}</ui-button>
|
2018-02-12 23:48:01 +09:00
|
|
|
</template>
|
2018-12-29 22:10:54 +09:00
|
|
|
<div v-if="data && !$store.state.i.twoFactorEnabled">
|
2018-02-12 23:48:01 +09:00
|
|
|
<ol>
|
2018-12-11 23:41:27 +09:00
|
|
|
<li>{{ $t('authenticator') }}<a href="https://support.google.com/accounts/answer/1066447" target="_blank">{{ $t('howtoinstall') }}</a></li>
|
2018-11-09 03:44:35 +09:00
|
|
|
<li>{{ $t('scan') }}<br><img :src="data.qr"></li>
|
|
|
|
<li>{{ $t('done') }}<br>
|
2018-12-29 22:10:54 +09:00
|
|
|
<ui-input v-model="token">{{ $t('token') }}</ui-input>
|
2018-11-09 03:44:35 +09:00
|
|
|
<ui-button primary @click="submit">{{ $t('submit') }}</ui-button>
|
2018-02-12 23:48:01 +09:00
|
|
|
</li>
|
|
|
|
</ol>
|
2018-12-29 22:10:54 +09:00
|
|
|
<ui-info>{{ $t('info') }}</ui-info>
|
2018-02-12 23:48:01 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2019-03-01 10:42:28 +09:00
|
|
|
import i18n from '../../../../i18n';
|
2018-02-12 23:48:01 +09:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-09 03:44:35 +09:00
|
|
|
i18n: i18n('desktop/views/components/settings.2fa.vue'),
|
2018-02-12 23:48:01 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
data: null,
|
|
|
|
token: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
register() {
|
2018-12-02 20:10:53 +09:00
|
|
|
this.$root.dialog({
|
2018-11-09 03:44:35 +09:00
|
|
|
title: this.$t('enter-password'),
|
2018-12-02 20:10:53 +09:00
|
|
|
input: {
|
|
|
|
type: 'password'
|
|
|
|
}
|
|
|
|
}).then(({ canceled, result: password }) => {
|
|
|
|
if (canceled) return;
|
2018-11-09 08:13:34 +09:00
|
|
|
this.$root.api('i/2fa/register', {
|
2018-02-12 23:48:01 +09:00
|
|
|
password: password
|
|
|
|
}).then(data => {
|
|
|
|
this.data = data;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
unregister() {
|
2018-12-02 20:10:53 +09:00
|
|
|
this.$root.dialog({
|
2018-11-09 03:44:35 +09:00
|
|
|
title: this.$t('enter-password'),
|
2018-12-02 20:10:53 +09:00
|
|
|
input: {
|
|
|
|
type: 'password'
|
|
|
|
}
|
|
|
|
}).then(({ canceled, result: password }) => {
|
|
|
|
if (canceled) return;
|
2018-11-09 08:13:34 +09:00
|
|
|
this.$root.api('i/2fa/unregister', {
|
2018-02-12 23:48:01 +09:00
|
|
|
password: password
|
|
|
|
}).then(() => {
|
2018-11-09 16:00:29 +09:00
|
|
|
this.$notify(this.$t('unregistered'));
|
2018-05-27 13:49:09 +09:00
|
|
|
this.$store.state.i.twoFactorEnabled = false;
|
2018-02-12 23:48:01 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
submit() {
|
2018-11-09 08:13:34 +09:00
|
|
|
this.$root.api('i/2fa/done', {
|
2018-02-12 23:48:01 +09:00
|
|
|
token: this.token
|
|
|
|
}).then(() => {
|
2018-11-09 16:00:29 +09:00
|
|
|
this.$notify(this.$t('success'));
|
2018-05-27 13:49:09 +09:00
|
|
|
this.$store.state.i.twoFactorEnabled = true;
|
2018-02-12 23:48:01 +09:00
|
|
|
}).catch(() => {
|
2018-11-09 16:00:29 +09:00
|
|
|
this.$notify(this.$t('failed'));
|
2018-02-12 23:48:01 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|