2023-09-22 07:12:33 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-09-22 07:12:33 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<MkModalWindow
|
|
|
|
ref="dialog"
|
|
|
|
:width="370"
|
|
|
|
:height="400"
|
|
|
|
@close="onClose"
|
|
|
|
@closed="emit('closed')"
|
|
|
|
>
|
|
|
|
<template #header>{{ i18n.ts.authentication }}</template>
|
|
|
|
|
|
|
|
<MkSpacer :marginMin="20" :marginMax="28">
|
|
|
|
<div style="padding: 0 0 16px 0; text-align: center;">
|
2023-09-23 05:24:33 +02:00
|
|
|
<img src="/fluent-emoji/1f510.png" alt="🔐" style="display: block; margin: 0 auto; width: 48px;">
|
|
|
|
<div style="margin-top: 16px;">{{ i18n.ts.authenticationRequiredToContinue }}</div>
|
2023-09-22 07:12:33 +02:00
|
|
|
</div>
|
|
|
|
|
2024-03-22 07:03:21 +01:00
|
|
|
<form @submit.prevent="done">
|
|
|
|
<div class="_gaps">
|
|
|
|
<MkInput ref="passwordInput" v-model="password" :placeholder="i18n.ts.password" type="password" autocomplete="current-password webauthn" required :withPasswordToggle="true">
|
2024-03-24 12:53:52 +01:00
|
|
|
<template #prefix><i class="ph-password ph-bold ph-lg"></i></template>
|
2024-03-22 07:03:21 +01:00
|
|
|
</MkInput>
|
2023-09-22 07:12:33 +02:00
|
|
|
|
2024-03-22 07:03:21 +01:00
|
|
|
<MkInput v-if="$i.twoFactorEnabled" v-model="token" type="text" :pattern="isBackupCode ? '^[A-Z0-9]{32}$' :'^[0-9]{6}$'" autocomplete="one-time-code" required :spellcheck="false" :inputmode="isBackupCode ? undefined : 'numeric'">
|
|
|
|
<template #label>{{ i18n.ts.token }} ({{ i18n.ts['2fa'] }})</template>
|
2024-03-24 12:53:52 +01:00
|
|
|
<template #prefix><i v-if="isBackupCode" class="ph-keyhole ph-bold ph-lg"></i><i v-else class="ph-math-operations ph-bold ph-lg"></i></template>
|
2024-03-22 07:03:21 +01:00
|
|
|
<template #caption><button class="_textButton" type="button" @click="isBackupCode = !isBackupCode">{{ isBackupCode ? i18n.ts.useTotp : i18n.ts.useBackupCode }}</button></template>
|
|
|
|
</MkInput>
|
2023-09-22 07:12:33 +02:00
|
|
|
|
2024-03-24 12:53:52 +01:00
|
|
|
<MkButton :disabled="(password ?? '') == '' || ($i.twoFactorEnabled && (token ?? '') == '')" type="submit" primary rounded style="margin: 0 auto;"><i class="ph-lock ph-bold ph-lg-open"></i> {{ i18n.ts.continue }}</MkButton>
|
2024-03-22 07:03:21 +01:00
|
|
|
</div>
|
|
|
|
</form>
|
2023-09-22 07:12:33 +02:00
|
|
|
</MkSpacer>
|
|
|
|
</MkModalWindow>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { onMounted, shallowRef, ref } from 'vue';
|
2023-09-22 07:12:33 +02:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import MkModalWindow from '@/components/MkModalWindow.vue';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2024-01-05 07:25:26 +01:00
|
|
|
import { signinRequired } from '@/account.js';
|
|
|
|
|
|
|
|
const $i = signinRequired();
|
2023-09-22 07:12:33 +02:00
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'done', v: { password: string; token: string | null; }): void;
|
|
|
|
(ev: 'closed'): void;
|
|
|
|
(ev: 'cancelled'): void;
|
|
|
|
}>();
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const dialog = shallowRef<InstanceType<typeof MkModalWindow>>();
|
|
|
|
const passwordInput = shallowRef<InstanceType<typeof MkInput>>();
|
|
|
|
const password = ref('');
|
2024-03-22 07:03:21 +01:00
|
|
|
const isBackupCode = ref(false);
|
2023-12-26 06:19:35 +01:00
|
|
|
const token = ref<string | null>(null);
|
2023-09-22 07:12:33 +02:00
|
|
|
|
|
|
|
function onClose() {
|
|
|
|
emit('cancelled');
|
2023-12-07 06:42:09 +01:00
|
|
|
if (dialog.value) dialog.value.close();
|
2023-09-22 07:12:33 +02:00
|
|
|
}
|
|
|
|
|
2024-03-22 07:03:21 +01:00
|
|
|
function done() {
|
2023-12-07 06:42:09 +01:00
|
|
|
emit('done', { password: password.value, token: token.value });
|
|
|
|
if (dialog.value) dialog.value.close();
|
2023-09-22 07:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
2023-12-07 06:42:09 +01:00
|
|
|
if (passwordInput.value) passwordInput.value.focus();
|
2023-09-22 07:12:33 +02:00
|
|
|
});
|
|
|
|
</script>
|