From 4cb1773147d65344b52b129b8f78da4ea4ceaf73 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 22 Dec 2024 15:50:39 +0900 Subject: [PATCH] =?UTF-8?q?feat(sign-in):=20=E3=83=A1=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=82=A2=E3=83=89=E3=83=AC=E3=82=B9=E3=83=AD=E3=82=B0=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=92=E5=AE=9F=E8=A3=85=20(MisskeyIO#836)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: まっちゃてぃー。 <56515516+mattyatea@users.noreply.github.com> --- .../src/server/api/SigninApiService.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/server/api/SigninApiService.ts b/packages/backend/src/server/api/SigninApiService.ts index 1d983ca4bc..00f5bf2e79 100644 --- a/packages/backend/src/server/api/SigninApiService.ts +++ b/packages/backend/src/server/api/SigninApiService.ts @@ -13,7 +13,6 @@ import type { SigninsRepository, UserProfilesRepository, UserSecurityKeysRepository, - UsersRepository, } from '@/models/_.js'; import type { Config } from '@/config.js'; import { getIpHash } from '@/misc/get-ip-hash.js'; @@ -38,9 +37,6 @@ export class SigninApiService { @Inject(DI.meta) private meta: MiMeta, - @Inject(DI.usersRepository) - private usersRepository: UsersRepository, - @Inject(DI.userProfilesRepository) private userProfilesRepository: UserProfilesRepository, @@ -114,12 +110,24 @@ export class SigninApiService { } // Fetch user - const user = await this.usersRepository.findOneBy({ - usernameLower: username.toLowerCase(), - host: IsNull(), - }) as MiLocalUser; + const profile = await this.userProfilesRepository.findOne({ + relations: ['user'], + where: username.includes('@') ? { + email: username, + emailVerified: true, + user: { + host: IsNull(), + } + } : { + user: { + usernameLower: username.toLowerCase(), + host: IsNull(), + }, + }, + }); + const user = (profile?.user as MiLocalUser) ?? null; - if (user == null) { + if (user == null || profile == null) { return error(404, { id: '6cc579cc-885d-43d8-95c2-b8c7fc963280', }); @@ -130,8 +138,6 @@ export class SigninApiService { id: 'e03a5f46-d309-4865-9b69-56282d94e1eb', }); } - - const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id }); const securityKeysAvailable = await this.userSecurityKeysRepository.countBy({ userId: user.id }).then(result => result >= 1); if (password == null) {