fix document 500 error and fix users tabel for bot
This commit is contained in:
@@ -4,6 +4,7 @@ import { authenticator } from 'otplib';
|
||||
import { EncryptionService } from '../infra/encryption.service';
|
||||
import { PrismaService } from '../infra/prisma.service';
|
||||
import { SettingsService } from './settings.service';
|
||||
import { AccessService } from './access.service';
|
||||
|
||||
@Injectable()
|
||||
export class TotpService {
|
||||
@@ -12,7 +13,8 @@ export class TotpService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly encryption: EncryptionService,
|
||||
private readonly settings: SettingsService
|
||||
private readonly settings: SettingsService,
|
||||
private readonly access: AccessService
|
||||
) {}
|
||||
|
||||
async getStatus(userId: string) {
|
||||
@@ -91,6 +93,19 @@ export class TotpService {
|
||||
return { isEnabled: false };
|
||||
}
|
||||
|
||||
async adminDisable(actorUserId: string, targetUserId: string) {
|
||||
await this.access.assertSuperAdmin(actorUserId);
|
||||
await this.ensureUserExists(targetUserId);
|
||||
|
||||
const record = await this.prisma.userTotpSecret.findUnique({ where: { userId: targetUserId } });
|
||||
if (!record?.isEnabled) {
|
||||
throw new BadRequestException('Двухфакторная аутентификация не включена');
|
||||
}
|
||||
|
||||
await this.prisma.userTotpSecret.delete({ where: { userId: targetUserId } });
|
||||
return { isEnabled: false };
|
||||
}
|
||||
|
||||
async verifyEnabledCode(userId: string, code: string) {
|
||||
const record = await this.prisma.userTotpSecret.findUnique({ where: { userId } });
|
||||
if (!record?.isEnabled) {
|
||||
|
||||
Reference in New Issue
Block a user