update: add label and issuer from the method of service
This commit is contained in:
@@ -2,7 +2,7 @@ import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Patch, Post } from
|
||||
import { ApiBadRequestResponse, ApiOperation, ApiResponse, ApiTags, ApiUnauthorizedResponse } from "@nestjs/swagger";
|
||||
|
||||
import { ChangePasswordDto } from "./DTO/change-password.dto";
|
||||
import { Enable2FADto, GenerateBackupCodesDto, Setup2FADto, UseBackupCodeDto, Verify2FADto } from "./DTO/create-two-factor.dto";
|
||||
import { Enable2FADto, GenerateBackupCodesDto, UseBackupCodeDto, Verify2FADto } from "./DTO/create-two-factor.dto";
|
||||
import { LoginDto } from "./DTO/login.dto";
|
||||
import { RefreshTokenDto } from "./DTO/refresh-token.dto";
|
||||
import { AuthService } from "./services/auth.service";
|
||||
@@ -55,16 +55,16 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Post("setup")
|
||||
@Post("2fa/setup")
|
||||
@ApiOperation({ summary: "Setup TOTP 2FA for user" })
|
||||
@ApiResponse({ status: 200, description: "2FA setup initiated successfully" })
|
||||
@ApiResponse({ status: 400, description: "Failed to setup 2FA" })
|
||||
setup2FA(@UserDec("wildduckUserId") wildduckUserId: string, @Body() setup2FADto: Setup2FADto) {
|
||||
return this.twoFactorService.setup2FA(wildduckUserId, setup2FADto);
|
||||
setup2FA(@UserDec("wildduckUserId") wildduckUserId: string) {
|
||||
return this.twoFactorService.setup2FA(wildduckUserId);
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Post("enable")
|
||||
@Post("2fa/enable")
|
||||
@ApiOperation({ summary: "Enable TOTP 2FA after verification" })
|
||||
@ApiResponse({ status: 200, description: "2FA enabled successfully" })
|
||||
@ApiResponse({ status: 400, description: "Invalid 2FA token or failed to enable 2FA" })
|
||||
@@ -73,7 +73,7 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Post("verify")
|
||||
@Post("2fa/verify")
|
||||
@ApiOperation({ summary: "Verify TOTP token" })
|
||||
@ApiResponse({ status: 200, description: "2FA token verification result" })
|
||||
verify2FA(@UserDec("wildduckUserId") wildduckUserId: string, @Body() verify2FADto: Verify2FADto) {
|
||||
@@ -81,7 +81,7 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Get("status")
|
||||
@Get("2fa/status")
|
||||
@ApiOperation({ summary: "Get 2FA status for user" })
|
||||
@ApiResponse({ status: 200, description: "2FA status retrieved successfully" })
|
||||
@ApiResponse({ status: 400, description: "Failed to get 2FA status" })
|
||||
@@ -90,7 +90,7 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Delete("disable")
|
||||
@Delete("2fa/disable")
|
||||
@ApiOperation({ summary: "Disable 2FA for user" })
|
||||
@ApiResponse({ status: 200, description: "2FA disabled successfully" })
|
||||
@ApiResponse({ status: 400, description: "Failed to disable 2FA" })
|
||||
@@ -99,7 +99,7 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Post("backup-codes/generate")
|
||||
@Post("2fa/backup-codes/generate")
|
||||
@ApiOperation({ summary: "Generate new backup codes" })
|
||||
@ApiResponse({ status: 200, description: "Backup codes generated successfully" })
|
||||
@ApiResponse({ status: 400, description: "2FA must be enabled to generate backup codes" })
|
||||
@@ -108,7 +108,7 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@AuthGuards()
|
||||
@Post("backup-codes/use")
|
||||
@Post("2fa/backup-codes/use")
|
||||
@ApiOperation({ summary: "Use backup code for authentication" })
|
||||
@ApiResponse({ status: 200, description: "Backup code verification result" })
|
||||
useBackupCode(@UserDec("wildduckUserId") wildduckUserId: string, @Body() useBackupCodeDto: UseBackupCodeDto) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { TwoFactorMessage, UserMessage } from "../../../common/enums/message.enu
|
||||
import { MailServerService } from "../../mail-server/services/mail-server.service";
|
||||
import { User } from "../../users/entities/user.entity";
|
||||
import { UserRepository } from "../../users/repositories/user.repository";
|
||||
import { Enable2FADto, Setup2FADto, UseBackupCodeDto, Verify2FADto } from "../DTO/create-two-factor.dto";
|
||||
import { Enable2FADto, UseBackupCodeDto, Verify2FADto } from "../DTO/create-two-factor.dto";
|
||||
|
||||
@Injectable()
|
||||
export class TwoFactorService {
|
||||
@@ -17,11 +17,15 @@ export class TwoFactorService {
|
||||
) {}
|
||||
|
||||
//==============================================
|
||||
async setup2FA(wildduckUserId: string, setup2FADto: Setup2FADto) {
|
||||
async setup2FA(wildduckUserId: string) {
|
||||
const user = await this.userRepository.findOne({ wildduckUserId });
|
||||
|
||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
const response = await firstValueFrom(
|
||||
this.mailServerService.twoFactor.setupTOTP(wildduckUserId, {
|
||||
issuer: setup2FADto.issuer || "DMail Service",
|
||||
label: setup2FADto.label || "DMail Service",
|
||||
issuer: "DMail Service",
|
||||
label: user.emailAddress,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user