summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkPasswordDialog.vue
blob: c49526d8e25fd0e9b9b29bc1db01713349ed5935 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
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;">
			<img src="/fluent-emoji/1f510.png" alt="🔐" style="display: block; margin: 0 auto; width: 48px;">
			<div style="margin-top: 16px;">{{ i18n.ts.authenticationRequiredToContinue }}</div>
		</div>

		<div class="_gaps">
			<MkInput ref="passwordInput" v-model="password" :placeholder="i18n.ts.password" type="password" autocomplete="current-password webauthn" :withPasswordToggle="true">
				<template #prefix><i class="ti ti-password"></i></template>
			</MkInput>

			<MkInput v-if="$i.twoFactorEnabled" v-model="token" type="text" pattern="^([0-9]{6}|[A-Z0-9]{32})$" autocomplete="one-time-code" :spellcheck="false">
				<template #label>{{ i18n.ts.token }} ({{ i18n.ts['2fa'] }})</template>
				<template #prefix><i class="ti ti-123"></i></template>
			</MkInput>

			<MkButton :disabled="(password ?? '') == '' || ($i.twoFactorEnabled && (token ?? '') == '')" primary rounded style="margin: 0 auto;" @click="done"><i class="ti ti-lock-open"></i> {{ i18n.ts.continue }}</MkButton>
		</div>
	</MkSpacer>
</MkModalWindow>
</template>

<script lang="ts" setup>
import { onMounted, shallowRef, ref } from 'vue';
import MkInput from '@/components/MkInput.vue';
import MkButton from '@/components/MkButton.vue';
import MkModalWindow from '@/components/MkModalWindow.vue';
import { i18n } from '@/i18n.js';
import { signinRequired } from '@/account.js';

const $i = signinRequired();

const emit = defineEmits<{
	(ev: 'done', v: { password: string; token: string | null; }): void;
	(ev: 'closed'): void;
	(ev: 'cancelled'): void;
}>();

const dialog = shallowRef<InstanceType<typeof MkModalWindow>>();
const passwordInput = shallowRef<InstanceType<typeof MkInput>>();
const password = ref('');
const token = ref<string | null>(null);

function onClose() {
	emit('cancelled');
	if (dialog.value) dialog.value.close();
}

function done(res) {
	emit('done', { password: password.value, token: token.value });
	if (dialog.value) dialog.value.close();
}

onMounted(() => {
	if (passwordInput.value) passwordInput.value.focus();
});
</script>