refactor(client): refactor settings/security to use Composition API (#8592)

This commit is contained in:
Andreas Nedbal 2022-05-04 03:10:34 +02:00 committed by GitHub
parent 1f222e6cd1
commit f8c66be130
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,17 +1,17 @@
<template> <template>
<div class="_formRoot"> <div class="_formRoot">
<FormSection> <FormSection>
<template #label>{{ $ts.password }}</template> <template #label>{{ i18n.ts.password }}</template>
<FormButton primary @click="change()">{{ $ts.changePassword }}</FormButton> <FormButton primary @click="change()">{{ i18n.ts.changePassword }}</FormButton>
</FormSection> </FormSection>
<FormSection> <FormSection>
<template #label>{{ $ts.twoStepAuthentication }}</template> <template #label>{{ i18n.ts.twoStepAuthentication }}</template>
<X2fa/> <X2fa/>
</FormSection> </FormSection>
<FormSection> <FormSection>
<template #label>{{ $ts.signinHistory }}</template> <template #label>{{ i18n.ts.signinHistory }}</template>
<MkPagination :pagination="pagination"> <MkPagination :pagination="pagination">
<template v-slot="{items}"> <template v-slot="{items}">
<div> <div>
@ -30,15 +30,15 @@
<FormSection> <FormSection>
<FormSlot> <FormSlot>
<FormButton danger @click="regenerateToken"><i class="fas fa-sync-alt"></i> {{ $ts.regenerateLoginToken }}</FormButton> <FormButton danger @click="regenerateToken"><i class="fas fa-sync-alt"></i> {{ i18n.ts.regenerateLoginToken }}</FormButton>
<template #caption>{{ $ts.regenerateLoginTokenDescription }}</template> <template #caption>{{ i18n.ts.regenerateLoginTokenDescription }}</template>
</FormSlot> </FormSlot>
</FormSection> </FormSection>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { defineExpose } from 'vue';
import FormSection from '@/components/form/section.vue'; import FormSection from '@/components/form/section.vue';
import FormSlot from '@/components/form/slot.vue'; import FormSlot from '@/components/form/slot.vue';
import FormButton from '@/components/ui/button.vue'; import FormButton from '@/components/ui/button.vue';
@ -46,77 +46,63 @@ import MkPagination from '@/components/ui/pagination.vue';
import X2fa from './2fa.vue'; import X2fa from './2fa.vue';
import * as os from '@/os'; import * as os from '@/os';
import * as symbols from '@/symbols'; import * as symbols from '@/symbols';
import { i18n } from '@/i18n';
export default defineComponent({ const pagination = {
components: { endpoint: 'i/signin-history' as const,
FormSection, limit: 5,
FormButton, };
MkPagination,
FormSlot,
X2fa,
},
emits: ['info'], async function change() {
const { canceled: canceled1, result: currentPassword } = await os.inputText({
title: i18n.ts.currentPassword,
type: 'password'
});
if (canceled1) return;
data() { const { canceled: canceled2, result: newPassword } = await os.inputText({
return { title: i18n.ts.newPassword,
[symbols.PAGE_INFO]: { type: 'password'
title: this.$ts.security, });
icon: 'fas fa-lock', if (canceled2) return;
bg: 'var(--bg)',
},
pagination: {
endpoint: 'i/signin-history' as const,
limit: 5,
},
}
},
methods: { const { canceled: canceled3, result: newPassword2 } = await os.inputText({
async change() { title: i18n.ts.newPasswordRetype,
const { canceled: canceled1, result: currentPassword } = await os.inputText({ type: 'password'
title: this.$ts.currentPassword, });
type: 'password' if (canceled3) return;
});
if (canceled1) return;
const { canceled: canceled2, result: newPassword } = await os.inputText({ if (newPassword !== newPassword2) {
title: this.$ts.newPassword, os.alert({
type: 'password' type: 'error',
}); text: i18n.ts.retypedNotMatch
if (canceled2) return; });
return;
}
const { canceled: canceled3, result: newPassword2 } = await os.inputText({ os.apiWithDialog('i/change-password', {
title: this.$ts.newPasswordRetype, currentPassword,
type: 'password' newPassword
}); });
if (canceled3) return; }
if (newPassword !== newPassword2) { function regenerateToken() {
os.alert({ os.inputText({
type: 'error', title: i18n.ts.password,
text: this.$ts.retypedNotMatch type: 'password'
}); }).then(({ canceled, result: password }) => {
return; if (canceled) return;
} os.api('i/regenerate_token', {
password: password
});
});
}
os.apiWithDialog('i/change-password', { defineExpose({
currentPassword, [symbols.PAGE_INFO]: {
newPassword title: i18n.ts.security,
}); icon: 'fas fa-lock',
}, bg: 'var(--bg)',
regenerateToken() {
os.inputText({
title: this.$ts.password,
type: 'password'
}).then(({ canceled, result: password }) => {
if (canceled) return;
os.api('i/regenerate_token', {
password: password
});
});
},
} }
}); });
</script> </script>