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.
- Loading branch information
Showing
14 changed files
with
259 additions
and
27 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
63 changes: 63 additions & 0 deletions
63
packages/backend/src/server/api/endpoints/users/get-twofactor-enable.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,63 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
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'; | ||
|
||
export const meta = { | ||
tags: ['users'], | ||
|
||
requireCredential: false, | ||
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' }, | ||
}, | ||
required: ['email'], | ||
} 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 userProfile = await this.userProfilesRepository.findOneBy({ | ||
email: ps.email, | ||
}); | ||
|
||
return userProfile ? { | ||
twoFactorEnabled: userProfile.twoFactorEnabled, | ||
usePasswordLessLogin: userProfile.usePasswordLessLogin, | ||
securityKeys: userProfile.twoFactorEnabled | ||
? await this.userSecurityKeysRepository.countBy({ userId: userProfile.userId }).then(result => result >= 1) | ||
: false, | ||
} : { | ||
twoFactorEnabled: false, | ||
usePasswordLessLogin: false, | ||
securityKeys: 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
Oops, something went wrong.