1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-30 06:28:31 +09:00
misskey/src/client/app/desktop/views/components/settings.2fa.vue

81 lines
2.0 KiB
Vue
Raw Normal View History

2018-02-12 23:48:01 +09:00
<template>
2018-02-22 01:25:57 +09:00
<div class="2fa">
2018-04-15 01:04:40 +09:00
<p>%i18n:@intro%<a href="%i18n:@url%" target="_blank">%i18n:@detail%</a></p>
<div class="ui info warn"><p>%fa:exclamation-triangle%%i18n:@caution%</p></div>
<p v-if="!data && !os.i.twoFactorEnabled"><button @click="register" class="ui primary">%i18n:@register%</button></p>
2018-04-08 03:58:11 +09:00
<template v-if="os.i.twoFactorEnabled">
2018-04-15 01:04:40 +09:00
<p>%i18n:@already-registered%</p>
<button @click="unregister" class="ui">%i18n:@unregister%</button>
2018-02-12 23:48:01 +09:00
</template>
<div v-if="data">
<ol>
2018-04-15 01:04:40 +09:00
<li>%i18n:@authenticator% <a href="https://support.google.com/accounts/answer/1066447" target="_blank">%i18n:@howtoinstall%</a></li>
<li>%i18n:@scan%<br><img :src="data.qr"></li>
<li>%i18n:@done%<br>
2018-02-12 23:48:01 +09:00
<input type="number" v-model="token" class="ui">
2018-04-15 01:04:40 +09:00
<button @click="submit" class="ui primary">%i18n:@submit%</button>
2018-02-12 23:48:01 +09:00
</li>
</ol>
2018-04-15 01:04:40 +09:00
<div class="ui info"><p>%fa:info-circle%%i18n:@info%</p></div>
2018-02-12 23:48:01 +09:00
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
data() {
return {
data: null,
token: null
};
},
methods: {
register() {
2018-02-22 01:25:57 +09:00
(this as any).apis.input({
2018-04-16 07:07:32 +09:00
title: '%i18n:!@enter-password%',
2018-02-22 01:25:57 +09:00
type: 'password'
}).then(password => {
2018-02-18 12:35:18 +09:00
(this as any).api('i/2fa/register', {
2018-02-12 23:48:01 +09:00
password: password
}).then(data => {
this.data = data;
});
});
},
unregister() {
2018-02-22 01:25:57 +09:00
(this as any).apis.input({
2018-04-16 07:07:32 +09:00
title: '%i18n:!@enter-password%',
2018-02-22 01:25:57 +09:00
type: 'password'
}).then(password => {
2018-02-18 12:35:18 +09:00
(this as any).api('i/2fa/unregister', {
2018-02-12 23:48:01 +09:00
password: password
}).then(() => {
2018-04-16 07:07:32 +09:00
(this as any).apis.notify('%i18n:!@unregistered%');
2018-04-08 03:58:11 +09:00
(this as any).os.i.twoFactorEnabled = false;
2018-02-12 23:48:01 +09:00
});
});
},
submit() {
2018-02-18 12:35:18 +09:00
(this as any).api('i/2fa/done', {
2018-02-12 23:48:01 +09:00
token: this.token
}).then(() => {
2018-04-16 07:07:32 +09:00
(this as any).apis.notify('%i18n:!@success%');
2018-04-08 03:58:11 +09:00
(this as any).os.i.twoFactorEnabled = true;
2018-02-12 23:48:01 +09:00
}).catch(() => {
2018-04-16 07:07:32 +09:00
(this as any).apis.notify('%i18n:!@failed%');
2018-02-12 23:48:01 +09:00
});
}
}
});
</script>
<style lang="stylus" scoped>
2018-02-22 01:25:57 +09:00
.2fa
2018-02-12 23:48:01 +09:00
color #4a535a
</style>