From c452b28cfb583a0a31098c20fe75062ab2a156ea Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Wed, 27 Dec 2023 20:00:49 +0900 Subject: [PATCH 01/13] =?UTF-8?q?[chore]=20#6=20=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1=20=EA=B4=80=EB=A0=A8=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 21dcb21..3746422 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,14 @@ dependencies { annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta" // querydsl JPAAnnotationProcessor 사용 지정 annotationProcessor "jakarta.annotation:jakarta.annotation-api" // java.lang.NoClassDefFoundError (javax.annotation.Generated) 대응 코드 annotationProcessor "jakarta.persistence:jakarta.persistence-api" // java.lang.NoClassDefFoundError (javax.annotation.Entity) 대응 코드 + + // 이메일 SMTP + implementation 'org.springframework.boot:spring-boot-starter-mail' + + // thymeleaf + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' + } tasks.named('test') { From d3752ad37190656bd7622fc7617e7f6c9cd7b8a7 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:05:52 +0900 Subject: [PATCH 02/13] =?UTF-8?q?[feat]=20#6=20=EB=B0=9C=EC=86=A1=ED=95=A0?= =?UTF-8?q?=20=EB=A9=94=EC=9D=BC=20html=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/email.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/resources/templates/email.html diff --git a/src/main/resources/templates/email.html b/src/main/resources/templates/email.html new file mode 100644 index 0000000..53cac1d --- /dev/null +++ b/src/main/resources/templates/email.html @@ -0,0 +1,18 @@ + + + + + +
+

기숙사 룸메이트 매칭 플랫폼 Check-mate

+

반갑습니다.

+

아래 코드를 인증번호 입력 란에 입력해주세요.

+ +
+ +
+
+ + + + From d4064ed8019e1ad21b73052c7497142f47d01358 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:06:37 +0900 Subject: [PATCH 03/13] =?UTF-8?q?[feat]=20#6=20=EC=9D=B4=EB=A9=94=EC=9D=BC?= =?UTF-8?q?=20=EC=9D=B8=EC=A6=9D=20request=20dto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/dto/request/EmailPostRequestDto.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/dto/request/EmailPostRequestDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/request/EmailPostRequestDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/request/EmailPostRequestDto.java new file mode 100644 index 0000000..54640a8 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/request/EmailPostRequestDto.java @@ -0,0 +1,6 @@ +package org.gachon.checkmate.domain.member.dto.request; + +public record EmailPostRequestDto( + String email +) { +} From c0862088e3863ca16c6440561f8cac1ff91660b6 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:06:50 +0900 Subject: [PATCH 04/13] =?UTF-8?q?[feat]=20#6=20=EC=9D=B4=EB=A9=94=EC=9D=BC?= =?UTF-8?q?=20=EC=9D=B8=EC=A6=9D=20response=20dto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/dto/response/EmailResponseDto.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/dto/response/EmailResponseDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/response/EmailResponseDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/response/EmailResponseDto.java new file mode 100644 index 0000000..c9e0b69 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/response/EmailResponseDto.java @@ -0,0 +1,6 @@ +package org.gachon.checkmate.domain.member.dto.response; + +public record EmailResponseDto( + String code +) { +} From ffc3b40b1a18342d60f5cbb41a3598d0c0648c1b Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:07:19 +0900 Subject: [PATCH 05/13] =?UTF-8?q?[feat]=20#6=20=EC=9D=B4=EB=A9=94=EC=9D=BC?= =?UTF-8?q?=20=EC=9D=B8=EC=A6=9D=20member=20controller=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java new file mode 100644 index 0000000..0bc78f8 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java @@ -0,0 +1,26 @@ +package org.gachon.checkmate.domain.member.controller; + +import lombok.RequiredArgsConstructor; +import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; +import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; +import org.gachon.checkmate.domain.member.service.MemberService; +import org.gachon.checkmate.global.common.SuccessResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RequestMapping("/api/member") +@RestController +public class MemberController { + + private final MemberService memberService; + + @PostMapping("/email") + public ResponseEntity> sendMail(@RequestBody EmailPostRequestDto emailPostRequestDto) { + final EmailResponseDto emailResponseDto = memberService.sendMail(emailPostRequestDto, "email"); + return SuccessResponse.ok(emailResponseDto); + } +} From be63ecb8a98e4e55d00a92221743f688e7bd6bab Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:07:42 +0900 Subject: [PATCH 06/13] =?UTF-8?q?[feat]=20#6=20=EC=9D=B4=EB=A9=94=EC=9D=BC?= =?UTF-8?q?=20=EC=9D=B8=EC=A6=9D=20service=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java new file mode 100644 index 0000000..121f10b --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -0,0 +1,62 @@ +package org.gachon.checkmate.domain.member.service; + +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; +import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; +import org.gachon.checkmate.global.config.auth.jwt.JwtProvider; +import org.gachon.checkmate.global.error.exception.InternalServerException; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.thymeleaf.context.Context; +import org.thymeleaf.spring6.SpringTemplateEngine; + +import java.util.Random; + +import static org.gachon.checkmate.global.error.ErrorCode.EMAIL_SEND_ERROR; + +@Slf4j +@RequiredArgsConstructor +@Transactional +@Service +public class MemberService { + + private final JwtProvider jwtProvider; + private final JavaMailSender javaMailSender; + private final SpringTemplateEngine templateEngine; + + public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto, String type) { + String authNum = createNumericCode(); + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + try { + MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, "UTF-8"); + mimeMessageHelper.setTo(emailPostRequestDto.email()); // 메일 수신자 + mimeMessageHelper.setSubject("[CHECKMATE] 이메일 인증번호 발송"); // 메일 제목 + mimeMessageHelper.setText(setContext(authNum, type), true); // 메일 본문 + javaMailSender.send(mimeMessage); + return new EmailResponseDto(authNum); + } catch (MessagingException e) { + throw new InternalServerException(EMAIL_SEND_ERROR); + } + } + + public static String createNumericCode() { + Random random = new Random(); + StringBuilder code = new StringBuilder(); + for (int i = 0; i < 6; i++) { + code.append(random.nextInt(10)); + } + return code.toString(); + } + + public String setContext(String code, String type) { + Context context = new Context(); + context.setVariable("code", code); + return templateEngine.process(type, context); + } + +} From 6d383b8911663e684e5f4d83408f34486c5edace Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:08:55 +0900 Subject: [PATCH 07/13] =?UTF-8?q?[chore]=20#6=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=9D=B8=EC=A6=9D=20=EC=8B=9C=ED=81=90=EB=A6=AC?= =?UTF-8?q?=ED=8B=B0=20=EC=98=88=EC=99=B8=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/gachon/checkmate/global/config/auth/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java index 6fb9abb..8f3c23b 100644 --- a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java +++ b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java @@ -23,7 +23,7 @@ public class SecurityConfig { private final CorsConfig corsConfig; private final JwtProvider jwtProvider; - private static final String[] whiteList = {"/"}; + private static final String[] whiteList = {"/", "api/member/email"}; @Bean public WebSecurityCustomizer webSecurityCustomizer() { From 476e9c0c8d7d3114b8ae2fdec8d47a4b362813db Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:09:23 +0900 Subject: [PATCH 08/13] =?UTF-8?q?[feat]=20#6=20=EC=9D=B4=EB=A9=94=EC=9D=BC?= =?UTF-8?q?=20=EC=9D=B8=EC=A6=9D=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/gachon/checkmate/global/error/ErrorCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java index 095125c..9705dfa 100644 --- a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java +++ b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java @@ -49,7 +49,8 @@ public enum ErrorCode { /** * 500 Internal Server Error */ - INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류입니다."); + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류입니다."), + EMAIL_SEND_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "이메일 전송에 실패했습니다."); private final HttpStatus httpStatus; private final String message; From 10411ec3d834ef95f0d1db54c7a0ac7999bd0a04 Mon Sep 17 00:00:00 2001 From: JI YOUNG <101448999+ziiyouth@users.noreply.github.com> Date: Thu, 28 Dec 2023 00:27:34 +0900 Subject: [PATCH 09/13] Update cicd.yml --- .github/workflows/cicd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index d2e5124..8035019 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -31,7 +31,6 @@ jobs: - name: 🐧 application.yml 파일을 생성 합니다. run: | - mkdir ./src/main/resources touch ./src/main/resources/application.yml echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.yml # github actions에서 설정한 값을 application.yml 파일에 쓰기 From 5e6dc0592db9fcc7a4e7ec2d753e5248d1cabac7 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:54:10 +0900 Subject: [PATCH 10/13] =?UTF-8?q?[refactor]=20#6=20MailProvider=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 45 ++------------ .../global/config/mail/MailProvider.java | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index 121f10b..e05c86b 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -1,23 +1,13 @@ package org.gachon.checkmate.domain.member.service; -import jakarta.mail.MessagingException; -import jakarta.mail.internet.MimeMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; import org.gachon.checkmate.global.config.auth.jwt.JwtProvider; -import org.gachon.checkmate.global.error.exception.InternalServerException; -import org.springframework.mail.javamail.JavaMailSender; -import org.springframework.mail.javamail.MimeMessageHelper; +import org.gachon.checkmate.global.config.mail.MailProvider; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.thymeleaf.context.Context; -import org.thymeleaf.spring6.SpringTemplateEngine; - -import java.util.Random; - -import static org.gachon.checkmate.global.error.ErrorCode.EMAIL_SEND_ERROR; @Slf4j @RequiredArgsConstructor @@ -26,37 +16,10 @@ public class MemberService { private final JwtProvider jwtProvider; - private final JavaMailSender javaMailSender; - private final SpringTemplateEngine templateEngine; - - public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto, String type) { - String authNum = createNumericCode(); - MimeMessage mimeMessage = javaMailSender.createMimeMessage(); - try { - MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, "UTF-8"); - mimeMessageHelper.setTo(emailPostRequestDto.email()); // 메일 수신자 - mimeMessageHelper.setSubject("[CHECKMATE] 이메일 인증번호 발송"); // 메일 제목 - mimeMessageHelper.setText(setContext(authNum, type), true); // 메일 본문 - javaMailSender.send(mimeMessage); - return new EmailResponseDto(authNum); - } catch (MessagingException e) { - throw new InternalServerException(EMAIL_SEND_ERROR); - } - } - - public static String createNumericCode() { - Random random = new Random(); - StringBuilder code = new StringBuilder(); - for (int i = 0; i < 6; i++) { - code.append(random.nextInt(10)); - } - return code.toString(); - } + private final MailProvider mailProvider; - public String setContext(String code, String type) { - Context context = new Context(); - context.setVariable("code", code); - return templateEngine.process(type, context); + public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto) { + return mailProvider.sendMail(emailPostRequestDto, "email"); } } diff --git a/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java b/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java new file mode 100644 index 0000000..48c3a57 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java @@ -0,0 +1,58 @@ +package org.gachon.checkmate.global.config.mail; + +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; +import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; +import org.gachon.checkmate.global.error.exception.InternalServerException; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Component; +import org.thymeleaf.context.Context; +import org.thymeleaf.spring6.SpringTemplateEngine; + +import java.util.Random; + +import static org.gachon.checkmate.global.error.ErrorCode.EMAIL_SEND_ERROR; + +@Slf4j +@RequiredArgsConstructor +@Component +public class MailProvider { + + private final JavaMailSender javaMailSender; + private final SpringTemplateEngine templateEngine; + + public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto, String type) { + String authNum = createNumericCode(); + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + try { + MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, "UTF-8"); + mimeMessageHelper.setTo(emailPostRequestDto.email()); // 메일 수신자 + mimeMessageHelper.setSubject("[CHECKMATE] 이메일 인증번호 발송"); // 메일 제목 + mimeMessageHelper.setText(setContext(authNum, type), true); // 메일 본문 + javaMailSender.send(mimeMessage); + return new EmailResponseDto(authNum); + } catch (MessagingException e) { + throw new InternalServerException(EMAIL_SEND_ERROR); + } + } + + public static String createNumericCode() { + Random random = new Random(); + StringBuilder code = new StringBuilder(); + for (int i = 0; i < 6; i++) { + code.append(random.nextInt(10)); + } + return code.toString(); + } + + public String setContext(String code, String type) { + Context context = new Context(); + context.setVariable("code", code); + return templateEngine.process(type, context); + } + +} From c9d23a41581a9d8546238464848c7e3de0676bee Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:54:49 +0900 Subject: [PATCH 11/13] =?UTF-8?q?[refactor]=20#6=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=9D=B8=EC=A6=9D=20request=20=EC=9D=B8=EC=9E=90?= =?UTF-8?q?=20=EC=A0=84=EB=8B=AC=20=EA=B3=BC=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/member/controller/MemberController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java index 0bc78f8..58e883f 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java +++ b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java @@ -19,8 +19,8 @@ public class MemberController { private final MemberService memberService; @PostMapping("/email") - public ResponseEntity> sendMail(@RequestBody EmailPostRequestDto emailPostRequestDto) { - final EmailResponseDto emailResponseDto = memberService.sendMail(emailPostRequestDto, "email"); + public ResponseEntity> sendMail(@RequestBody final EmailPostRequestDto emailPostRequestDto) { + final EmailResponseDto emailResponseDto = memberService.sendMail(emailPostRequestDto); return SuccessResponse.ok(emailResponseDto); } } From 028a88dd2d54459c23f34d83df62b0080b9825e4 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 00:57:15 +0900 Subject: [PATCH 12/13] =?UTF-8?q?[refactor]=20#6=20MailProvider=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=20=EC=A0=9C=ED=95=9C=EC=9E=90=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/gachon/checkmate/global/config/mail/MailProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java b/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java index 48c3a57..7f6060c 100644 --- a/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java +++ b/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java @@ -40,7 +40,7 @@ public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto, String } } - public static String createNumericCode() { + private static String createNumericCode() { Random random = new Random(); StringBuilder code = new StringBuilder(); for (int i = 0; i < 6; i++) { @@ -49,7 +49,7 @@ public static String createNumericCode() { return code.toString(); } - public String setContext(String code, String type) { + private String setContext(String code, String type) { Context context = new Context(); context.setVariable("code", code); return templateEngine.process(type, context); From 8fa784c761723a511befe177b9dae7e2255c9f8e Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Thu, 28 Dec 2023 01:10:53 +0900 Subject: [PATCH 13/13] =?UTF-8?q?[refactor]=20#6=20MailProvider=20?= =?UTF-8?q?=EC=9D=B8=EC=9E=90=EA=B0=92,=20=EB=A6=AC=ED=84=B4=EA=B0=92=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/member/service/MemberService.java | 3 ++- .../gachon/checkmate/global/config/mail/MailProvider.java | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index e05c86b..5d27983 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -19,7 +19,8 @@ public class MemberService { private final MailProvider mailProvider; public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto) { - return mailProvider.sendMail(emailPostRequestDto, "email"); + String authNum = mailProvider.sendMail(emailPostRequestDto.email(), "email"); + return new EmailResponseDto(authNum); } } diff --git a/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java b/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java index 7f6060c..754a665 100644 --- a/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java +++ b/src/main/java/org/gachon/checkmate/global/config/mail/MailProvider.java @@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; -import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; import org.gachon.checkmate.global.error.exception.InternalServerException; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; @@ -25,16 +24,16 @@ public class MailProvider { private final JavaMailSender javaMailSender; private final SpringTemplateEngine templateEngine; - public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto, String type) { + public String sendMail(String email, String type) { String authNum = createNumericCode(); MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, "UTF-8"); - mimeMessageHelper.setTo(emailPostRequestDto.email()); // 메일 수신자 + mimeMessageHelper.setTo(email); // 메일 수신자 mimeMessageHelper.setSubject("[CHECKMATE] 이메일 인증번호 발송"); // 메일 제목 mimeMessageHelper.setText(setContext(authNum, type), true); // 메일 본문 javaMailSender.send(mimeMessage); - return new EmailResponseDto(authNum); + return authNum; } catch (MessagingException e) { throw new InternalServerException(EMAIL_SEND_ERROR); }