11import bcrypt from 'bcrypt' ;
22import { StatusCodes } from "http-status-codes" ;
3- import { postUserInfo } from "../services/auth.service.js" ;
4- import { getLoginInfo } from "../services/auth.service.js" ;
5- import { handleTokenRefreshService } from "../services/auth.service.js" ;
6- import { PasswordLengthError } from "../errors/auth.error.js" ;
7- import { createdGetLoginInfoDTO } from '../dtos/auth.dto.js' ;
3+ import { postUserInfo , getLoginInfo , handleTokenRefreshService , sendVerificationEmail , verifyEmailCode } from "../services/auth.service.js" ;
4+ import { PasswordLengthError , CodeNotValidateError } from "../errors/auth.error.js" ;
85
96// 회원가입
107export const handleSignUp = async ( req , res ) => {
@@ -252,7 +249,7 @@ export const handleLogin = async (req, res) => {
252249
253250 const { email, password } = req . body ;
254251
255- const userInfo = await getLoginInfo ( { email, password} ) ;
252+ const userInfo = await getLoginInfo ( { email, password } ) ;
256253
257254 res . status ( StatusCodes . OK ) . success ( userInfo ) ;
258255
@@ -335,15 +332,113 @@ export const handleTokenRefresh = async (req, res) => {
335332
336333}
337334
338- // 이메일 인증
335+ // 인증번호 발송
336+ export const handlesendEmail = async ( req , res ) => {
337+
338+ /*
339+ #swagger.summary = '인증번호 발송 API';
340+ #swagger.tags = ['Auth']
341+
342+ #swagger.requestBody = {
343+ required: true,
344+ content: {
345+ "application/json": {
346+ schema: {
347+ type: "object",
348+ properties: {
349+ email: { type: "string", example: "user@example .com" }
350+ },
351+ required: ["email"]
352+ }
353+ }
354+ }
355+ }
356+
357+ #swagger.responses[200] = {
358+ description: "인증번호 발송 성공 응답",
359+ content: {
360+ "application/json": {
361+ schema: {
362+ type: "object",
363+ properties: {
364+ resultType: { type: "string", example: "SUCCESS" },
365+ error: { type: "object", nullable: true, example: null },
366+ success: {
367+ type: "object",
368+ properties: {
369+ message: { type: "string", example: "인증번호가 전송되었습니다!" }
370+ }
371+ }
372+ }
373+ }
374+ }
375+ }
376+ }
377+
378+ #swagger.responses[400] = {
379+ description: "인증번호 발송 실패 응답",
380+ content: {
381+ "application/json": {
382+ schema: {
383+ type: "object",
384+ properties: {
385+ resultType: { type: "string", example: "FAIL" },
386+ error: {
387+ type: "object",
388+ properties: {
389+ errorCode: { type: "string", example: "A018" },
390+ reason: { type: "string", example: "이메일은 '@'를 포함하는 문자열이어야 합니다." },
391+ data: {
392+ type: "object",
393+ properties: {
394+ email: { type: "string", example: "user!example.com" }
395+ }
396+ }
397+ }
398+ },
399+ success: { type: "object", nullable: true, example: null }
400+ }
401+ }
402+ }
403+ }
404+ }
405+ */
406+
407+ console . log ( "인증번호 발송 요청" ) ;
408+
409+ const { email } = req . body ;
410+
411+ await sendVerificationEmail ( email ) ;
412+
413+ res . status ( StatusCodes . OK ) . success ( { message : '인증번호가 전송되었습니다!' } ) ;
414+
415+ }
416+
417+ // 인증번호 검증
339418export const handlecheckEmail = async ( req , res ) => {
340419
341420 /*
342- #swagger.summary = '이메일 인증 API';
421+ #swagger.summary = '인증번호 검증 API';
343422 #swagger.tags = ['Auth']
344423
424+ #swagger.requestBody = {
425+ required: true,
426+ content: {
427+ "application/json": {
428+ schema: {
429+ type: "object",
430+ properties: {
431+ email: { type: "string", example: "user@example .com" },
432+ code: { type: "string", example: "123456" }
433+ },
434+ required: ["email", "code"]
435+ }
436+ }
437+ }
438+ }
439+
345440 #swagger.responses[200] = {
346- description: "이메일 인증 성공 응답",
441+ description: "인증번호 검증 성공 응답",
347442 content: {
348443 "application/json": {
349444 schema: {
@@ -354,9 +449,7 @@ export const handlecheckEmail = async (req, res) => {
354449 success: {
355450 type: "object",
356451 properties: {
357- email: { type: "string", example: "user@example .com" },
358- accessToken: { type: "string", example: "accessToken" },
359- refreshToken: { type: "string", example: "refreshToken" }
452+ message: { type: "string", example: "인증되었습니다." }
360453 }
361454 }
362455 }
@@ -366,7 +459,63 @@ export const handlecheckEmail = async (req, res) => {
366459 }
367460
368461 #swagger.responses[400] = {
369- description: "이메일 인증 실패 응답",
462+ description: "인증번호 검증 실패 응답",
463+ content: {
464+ "application/json": {
465+ schema: {
466+ type: "object",
467+ properties: {
468+ resultType: { type: "string", example: "FAIL" },
469+ error: {
470+ type: "object",
471+ properties: {
472+ errorCode: { type: "string", example: "A018" },
473+ reason: { type: "string", example: "이메일은 '@'를 포함하는 문자열이어야 합니다." },
474+ data: {
475+ type: "object",
476+ properties: {
477+ email: { type: "string", example: "user!example.com" }
478+ }
479+ }
480+ }
481+ },
482+ success: { type: "object", nullable: true, example: null }
483+ }
484+ }
485+ }
486+ }
487+ }
488+
489+ #swagger.responses[401] = {
490+ description: "인증번호 검증 실패 응답",
491+ content: {
492+ "application/json": {
493+ schema: {
494+ type: "object",
495+ properties: {
496+ resultType: { type: "string", example: "FAIL" },
497+ error: {
498+ type: "object",
499+ properties: {
500+ errorCode: { type: "string", example: "A019" },
501+ reason: { type: "string", example: "인증번호는 6자리 숫자입니다." },
502+ data: {
503+ type: "object",
504+ properties: {
505+ code: { type: "string", example: "1234567" }
506+ }
507+ }
508+ }
509+ },
510+ success: { type: "object", nullable: true, example: null }
511+ }
512+ }
513+ }
514+ }
515+ }
516+
517+ #swagger.responses[402] = {
518+ description: "인증번호 검증 실패 응답",
370519 content: {
371520 "application/json": {
372521 schema: {
@@ -376,9 +525,9 @@ export const handlecheckEmail = async (req, res) => {
376525 error: {
377526 type: "object",
378527 properties: {
379- errorCode: { type: "string", example: "L003 " },
380- reason: { type: "string", example: "이메일 인증 실패 " },
381- data: { type: "object", nullable: true, example: {} }
528+ errorCode: { type: "string", example: "A020 " },
529+ reason: { type: "string", example: "인증번호가 올바르지 않습니다. " },
530+ data: { type: "object", example: {} }
382531 }
383532 },
384533 success: { type: "object", nullable: true, example: null }
@@ -389,5 +538,16 @@ export const handlecheckEmail = async (req, res) => {
389538 }
390539*/
391540
541+ console . log ( "인증번호 검증 요청" ) ;
542+
543+ const { email, code } = req . body ;
544+
545+ const isVerified = await verifyEmailCode ( email , code ) ;
546+
547+ if ( isVerified ) {
548+ return res . status ( StatusCodes . OK ) . success ( { message : '인증되었습니다.' } ) ;
549+ } else {
550+ throw new CodeNotValidateError ( "인증번호가 올바르지 않습니다." ) ;
551+ }
392552
393553}
0 commit comments