issue # 이메일 인증 코드 발송 로직 구현

This commit is contained in:
geonhee-min
2025-11-21 16:21:07 +09:00
parent 0170421d16
commit 6cd0361375
13 changed files with 118 additions and 6 deletions

View File

@@ -1,14 +1,27 @@
import { Controller, Get, Post, Query } from "@nestjs/common";
import { Body, Controller, Get, Post, Query } from "@nestjs/common";
import { CheckDuplicationRequestDto } from "./dto/checkDuplication/check-duplication-request.dto";
import { CheckDuplicationResponseDto } from "./dto/checkDuplication/check-duplication-response.dto";
import { AccountService } from "./account.service";
import { SendVerificationCodeRequestDto } from "./dto/checkDuplication/send-verification-code-request.dto";
import { SendVerificationCodeResponseDto } from "./dto/checkDuplication/send-verification-code-response.dto";
@Controller('account')
export class AccountController {
constructor(private readonly accountService: AccountService) {}
@Get('/')
async test() {
return "Test"
}
@Get('check-duplication')
async checkDuplication(@Query() query: CheckDuplicationRequestDto): Promise<CheckDuplicationResponseDto> {
return this.accountService.checkDuplication(query);
return await this.accountService.checkDuplication(query);
}
@Post('send-verification-code')
async sendVerificationCode(@Body() body: SendVerificationCodeRequestDto): Promise<SendVerificationCodeResponseDto> {
const result = await this.accountService.sendVerificationCode(body);
return result;
}
}

View File

@@ -5,6 +5,7 @@ import { AccountService } from "./account.service";
@Module({
controllers: [AccountController],
providers: [AccountService, AccountRepo]
providers: [AccountService, AccountRepo],
exports: [AccountService, AccountRepo]
})
export class AccountModule {}

View File

@@ -2,14 +2,33 @@ import { Injectable } from "@nestjs/common";
import { AccountRepo } from "./account.repo";
import { CheckDuplicationRequestDto } from "./dto/checkDuplication/check-duplication-request.dto";
import { CheckDuplicationResponseDto } from "./dto/checkDuplication/check-duplication-response.dto";
import { SendVerificationCodeRequestDto } from "./dto/checkDuplication/send-verification-code-request.dto";
import { MailerService } from "src/util/mailer/mailer.service";
import { Generator } from "src/util/generator";
import { SendVerificationCodeResponseDto } from "./dto/checkDuplication/send-verification-code-response.dto";
@Injectable()
export class AccountService {
constructor(private readonly accountRepo: AccountRepo) {}
constructor(
private readonly accountRepo: AccountRepo
, private readonly mailerService: MailerService
) {}
async checkDuplication(data: CheckDuplicationRequestDto): Promise<CheckDuplicationResponseDto> {
const count = await this.accountRepo.checkDuplication(data.type, data.value);
return { isDuplicated: count > 0 };
}
async sendVerificationCode(data: SendVerificationCodeRequestDto): Promise<SendVerificationCodeResponseDto> {
const code = Generator.getVerificationCode();
const html = `<p>Your verification code is: <strong style="font-size:16px;">${code}</strong></p>`;
const result = await this.mailerService.sendMail(data.email, "<Scheduler> 이메일 인증 코드", html);
if (result.rejected.length > 0) {
return { success: false, error: result.response }
} else {
return { success: true, message: "이메일 발송 완료" };
}
}
}

View File

@@ -0,0 +1,6 @@
import { IsEmail } from "@nestjs/class-validator";
export class SendVerificationCodeRequestDto {
@IsEmail()
email: string;
}

View File

@@ -0,0 +1,5 @@
export class SendVerificationCodeResponseDto {
success: boolean;
message?: string;
error?: string;
}