forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sign-in): メールアドレスログインを実装 (#836)
Co-authored-by: まっちゃてぃー。 <[email protected]>
- Loading branch information
Showing
14 changed files
with
236 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/backend/src/server/api/endpoints/users/get-security-info.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import type { UserProfilesRepository, UserSecurityKeysRepository } from '@/models/_.js'; | ||
import { Endpoint } from '@/server/api/endpoint-base.js'; | ||
import { DI } from '@/di-symbols.js'; | ||
import bcrypt from 'bcryptjs'; | ||
import ms from 'ms'; | ||
|
||
export const meta = { | ||
tags: ['users'], | ||
|
||
requireCredential: false, | ||
|
||
limit: { | ||
duration: ms('1hour'), | ||
max: 30, | ||
}, | ||
|
||
res: { | ||
type: 'object', | ||
properties: { | ||
twoFactorEnabled: { type: 'boolean' }, | ||
usePasswordLessLogin: { type: 'boolean' }, | ||
securityKeys: { type: 'boolean' }, | ||
}, | ||
}, | ||
errors: { | ||
}, | ||
} as const; | ||
|
||
export const paramDef = { | ||
type: 'object', | ||
properties: { | ||
email: { type: 'string' }, | ||
password: { type: 'string' }, | ||
}, | ||
required: ['email', 'password'], | ||
} as const; | ||
|
||
@Injectable() | ||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export | ||
constructor( | ||
@Inject(DI.userProfilesRepository) | ||
private userProfilesRepository: UserProfilesRepository, | ||
|
||
@Inject(DI.userSecurityKeysRepository) | ||
private userSecurityKeysRepository: UserSecurityKeysRepository, | ||
) { | ||
super(meta, paramDef, async (ps, me) => { | ||
const profile = await this.userProfilesRepository.findOneBy({ | ||
email: ps.email, | ||
emailVerified: true, | ||
}); | ||
|
||
const passwordMatched = await bcrypt.compare(ps.password, profile?.password ?? ''); | ||
if (!profile || !passwordMatched) { | ||
return { | ||
twoFactorEnabled: false, | ||
usePasswordLessLogin: false, | ||
securityKeys: false, | ||
}; | ||
} | ||
|
||
return { | ||
twoFactorEnabled: profile.twoFactorEnabled, | ||
usePasswordLessLogin: profile.usePasswordLessLogin, | ||
securityKeys: profile.twoFactorEnabled | ||
? await this.userSecurityKeysRepository.countBy({ userId: profile.userId }).then(result => result >= 1) | ||
: false, | ||
}; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.