Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Dec 22, 2024
1 parent b0ec08f commit 1ac4c69
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3722,6 +3722,10 @@ export interface Locale extends ILocale {
* モバイルデバイスのときドロワーで表示
*/
"useDrawerReactionPickerForMobile": string;
/**
* おかえりなさい
*/
"welcomeBack": string;
/**
* おかえりなさい、{name}さん
*/
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ incorrectTotp: "ワンタイムパスワードが間違っているか、期限
voteConfirm: "「{choice}」に投票しますか?"
hide: "隠す"
useDrawerReactionPickerForMobile: "モバイルデバイスのときドロワーで表示"
welcomeBack: "おかえりなさい"
welcomeBackWithName: "おかえりなさい、{name}さん"
clickToFinishEmailVerification: "[{ok}]を押して、メールアドレスの確認を完了してください。"
overridedDeviceKind: "デバイスタイプ"
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkSignin.input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SPDX-License-Identifier: AGPL-3.0-only
v-model="username"
:placeholder="isEmail ? i18n.ts.emailAddress : i18n.ts.username"
:type="isEmail ? 'email' : 'text'"
:pattern="isEmail ? '^[^@]+@[^@]+$' : undefined"
:pattern="isEmail ? undefined : '^[^@]+$'"
:spellcheck="false"
:autocomplete="isEmail ? 'email' : 'username webauthn'"
autofocus
Expand Down
22 changes: 18 additions & 4 deletions packages/frontend/src/components/MkSignin.password.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<div :class="$style.wrapper" data-cy-signin-page-password>
<div class="_gaps" :class="$style.root">
<div :class="$style.avatar" :style="{ backgroundImage: user ? `url('${user.avatarUrl}')` : undefined }"></div>
<div v-if="user" :class="$style.avatar" :style="{ backgroundImage: `url('${user.avatarUrl}')` }"></div>
<div v-else :class="[$style.avatar, $style.avatarFallback]">
<i class="ti ti-user"></i>
</div>
<div :class="$style.welcomeBackMessage">
<I18n :src="i18n.ts.welcomeBackWithName" tag="span">
<I18n v-if="user" :src="i18n.ts.welcomeBackWithName" tag="span">
<template #name><Mfm :text="user.name ?? user.username" :plain="true"/></template>
</I18n>
<span v-else>{{ i18n.ts.welcomeBack }}</span>
</div>

<!-- password入力 -->
<form class="_gaps_s" @submit.prevent="onSubmit">
<!-- ブラウザ オートコンプリート用 -->
<input type="hidden" name="username" autocomplete="username" :value="user.username">
<input v-if="user" type="hidden" name="username" autocomplete="username" :value="user.username">

<MkInput v-model="password" :placeholder="i18n.ts.password" type="password" autocomplete="current-password webauthn" :withPasswordToggle="true" required autofocus data-cy-signin-password>
<template #prefix><i class="ti ti-lock"></i></template>
Expand Down Expand Up @@ -63,7 +67,7 @@ import MkInput from '@/components/MkInput.vue';
import MkCaptcha from '@/components/MkCaptcha.vue';

const props = defineProps<{
user: Misskey.entities.UserDetailed;
user: Misskey.entities.UserDetailed | null;
needCaptcha: boolean;
}>();

Expand Down Expand Up @@ -147,6 +151,16 @@ defineExpose({
background-position: center;
background-size: cover;
border-radius: 100%;

&.avatarFallback {
background-color: var(--MI_THEME-accentedBg);
color: var(--MI_THEME-accent);
text-align: center;
height: 64px;
width: 64px;
font-size: 24px;
line-height: 64px;
}
}

.welcomeBackMessage {
Expand Down
31 changes: 19 additions & 12 deletions packages/frontend/src/components/MkSignin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SPDX-License-Identifier: AGPL-3.0-only
key="password"
ref="passwordPageEl"

:user="userInfo!"
:user="userInfo"
:needCaptcha="needCaptcha"

@passwordSubmitted="onPasswordSubmitted"
Expand Down Expand Up @@ -101,6 +101,7 @@ const waiting = ref(false);
const passwordPageEl = useTemplateRef('passwordPageEl');
const needCaptcha = ref(false);

const username = ref('');
const userInfo = ref<null | Misskey.entities.UserDetailed>(null);
const password = ref('');

Expand Down Expand Up @@ -141,7 +142,7 @@ function onPasskeyDone(credential: AuthenticationPublicKeyCredential): void {
}
emit('login', res.signinResponse);
}).catch(onSigninApiError);
} else if (userInfo.value != null) {
} else if (userInfo.value != null || username.value !== '') {
tryLogin({
username: userInfo.value.username,
password: password.value,
Expand All @@ -155,23 +156,26 @@ function onUseTotp(): void {
}
//#endregion

async function onUsernameSubmitted(username: string) {
async function onUsernameSubmitted(_username: string) {
waiting.value = true;
username.value = _username;

userInfo.value = await misskeyApi('users/show', {
username,
}).catch(() => null);
if (!_username.includes('@')) {
userInfo.value = await misskeyApi('users/show', {
username: _username,
}).catch(() => null);
}

await tryLogin({
username,
username: _username,
});
}

async function onPasswordSubmitted(pw: PwResponse) {
waiting.value = true;
password.value = pw.password;

if (userInfo.value == null) {
if (userInfo.value == null && username.value === '') {
await os.alert({
type: 'error',
title: i18n.ts.noSuchUser,
Expand All @@ -181,7 +185,7 @@ async function onPasswordSubmitted(pw: PwResponse) {
return;
} else {
await tryLogin({
username: userInfo.value.username,
username: userInfo.value?.username ?? username.value,
password: pw.password,
'hcaptcha-response': pw.captcha.hCaptchaResponse,
'm-captcha-response': pw.captcha.mCaptchaResponse,
Expand All @@ -195,7 +199,7 @@ async function onPasswordSubmitted(pw: PwResponse) {
async function onTotpSubmitted(token: string) {
waiting.value = true;

if (userInfo.value == null) {
if (userInfo.value == null && username.value === '') {
await os.alert({
type: 'error',
title: i18n.ts.noSuchUser,
Expand All @@ -205,7 +209,7 @@ async function onTotpSubmitted(token: string) {
return;
} else {
await tryLogin({
username: userInfo.value.username,
username: userInfo.value?.username ?? username.value,
password: password.value,
token,
});
Expand All @@ -214,7 +218,7 @@ async function onTotpSubmitted(token: string) {

async function tryLogin(req: Partial<Misskey.entities.SigninFlowRequest>): Promise<Misskey.entities.SigninFlowResponse> {
const _req = {
username: req.username ?? userInfo.value?.username,
username: req.username ?? userInfo.value?.username ?? username.value,
...req,
};

Expand Down Expand Up @@ -367,7 +371,9 @@ function onSigninApiError(err?: any): void {
if (doingPasskeyFromInputPage.value === true) {
doingPasskeyFromInputPage.value = false;
page.value = 'input';
username.value = '';
password.value = '';
userInfo.value = null;
}
passwordPageEl.value?.resetCaptcha();
nextTick(() => {
Expand All @@ -376,6 +382,7 @@ function onSigninApiError(err?: any): void {
}

onBeforeUnmount(() => {
username.value = '';
password.value = '';
needCaptcha.value = false;
userInfo.value = null;
Expand Down

0 comments on commit 1ac4c69

Please sign in to comment.