하석형 하석형 05-22
250522 하석형 이메일 인증 기능 구현, 이메일 메세지 영문 추가
@69cdb6dcc6c383aa00ee4561655ee153a3a78e9e
src/main/java/com/takensoft/common/verify/service/Impl/EmailServiceImpl.java
--- src/main/java/com/takensoft/common/verify/service/Impl/EmailServiceImpl.java
+++ src/main/java/com/takensoft/common/verify/service/Impl/EmailServiceImpl.java
@@ -1,5 +1,7 @@
 package com.takensoft.common.verify.service.Impl;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.takensoft.common.exception.*;
 import com.takensoft.common.util.JWTUtil;
 import com.takensoft.common.verify.dao.EmailDAO;
@@ -7,6 +9,7 @@
 import com.takensoft.common.verify.vo.EmailVO;
 import lombok.RequiredArgsConstructor;
 import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.dao.DataAccessException;
@@ -15,6 +18,8 @@
 import org.springframework.mail.javamail.JavaMailSender;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+
+import java.time.Duration;
 
 
 /**
@@ -36,7 +41,8 @@
     private final EmailDAO emailDAO;
     private final JWTUtil jwtUtil;
     private final JavaMailSender mailSender;
-    @Qualifier("redisTemplateObject")
+//    @Autowired
+//    @Qualifier("redisTemplateObject")
     private final RedisTemplate<String, Object> redisTemplate;
 
     @Value("${spring.mail.verifyTime}")
@@ -49,28 +55,23 @@
      * @param emailVO - 이메일 정보
      * @return boolean - 이메일 인증코드 발송 결과
      * @throws CustomEmailSendFailException - 이메일 발송 실패 시
-     * @throws DataAccessException - db 관련 예외 발생 시
      * @throws Exception - 그 외 예외 발생 시
      *
      * 이메일 인증코드 발송
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public boolean sendEmailVerifyCode(EmailVO emailVO){
+    public boolean sendEmailVerifyCode(EmailVO emailVO) {
         try {
             String email = emailVO.getEmail();
             String code = createRandomCode(); // 인증코드 생성
             emailVO.setCode(code);
-            long createdAt = System.currentTimeMillis(); // 현재 시간(millis)
-            emailVO.setCreatedAt(createdAt);
+            long currentAt = System.currentTimeMillis(); // 현재 시간(millis)
+            emailVO.setCreatedAt(currentAt);
 
             boolean isSend = redisTemplate.hasKey("email:" + email); // 이메일 인증코드 발송여부 확인
 
-            if(isSend) { // 이미 인증코드가 발송된 경우
-                EmailVO verifyVO = (EmailVO) redisTemplate.opsForValue().get("email:" + email); // 발송된 인증코드
-                if(createdAt - verifyVO.getCreatedAt() > verifyTime) { // 인증코드 유효시간이 지났을 경우
-                    redisTemplate.delete("email:" + email); // 인증코드 삭제
-                }
+            if (isSend) { // 이미 인증코드가 발송된 경우
+                redisTemplate.delete("email:" + email); // 인증코드 삭제
             }
 
             // 이메일 발송
@@ -84,10 +85,8 @@
                 throw new CustomEmailSendFailException("이메일 발송에 실패했습니다.");
             }
 
-            redisTemplate.opsForValue().set("email:" + email, emailVO, storeTime); // 인증코드 저장
+            redisTemplate.opsForValue().set("email:" + email, emailVO, Duration.ofMillis(storeTime)); // 인증코드 저장
             return true;
-        } catch (DataAccessException dae) {
-            throw dae;
         } catch (Exception e) {
             redisTemplate.delete("email:" + emailVO.getEmail()); // 실패시 인증코드 삭제
             throw e;
@@ -100,24 +99,22 @@
      * @throws CustomEmailVerifyExpireException - 이메일 인증 만료 시
      * @throws CustomEmailCodeNotMatchException - 이메일 인증코드 불일치 시
      * @throws CustomEmailVerifyFailException - 이메일 인증 실패 시
-     * @throws DataAccessException - db 관련 예외 발생 시
      * @throws Exception - 그 외 예외 발생 시
      *
      * 이메일 인증코드 확인
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public boolean checkEmailVerifyCode(EmailVO emailVO){
         try {
             String email = emailVO.getEmail();
             String code = emailVO.getCode();
-            long createdAt = System.currentTimeMillis(); // 현재 시간(millis)
+            long currentAt = System.currentTimeMillis(); // 현재 시간(millis)
 
             boolean isSend = redisTemplate.hasKey("email:" + email); // 이메일 인증코드 발송여부 확인
 
             if(isSend) { // 이미 인증코드가 발송된 경우
                 EmailVO verifyVO = (EmailVO) redisTemplate.opsForValue().get("email:" + email); // 발송된 인증코드
-                if(createdAt - verifyVO.getCreatedAt() > verifyTime) { // 인증코드 유효시간이 지났을 경우
+                if(currentAt - verifyVO.getCreatedAt() > verifyTime) { // 인증코드 유효시간이 지났을 경우
                     throw new CustomEmailVerifyExpireException("인증 시간이 만료되었습니다.");
                 }
                 String verifyCode = verifyVO.getCode(); // 발송된 인증코드
@@ -130,8 +127,6 @@
                 throw new CustomEmailVerifyFailException("이메일 인증에 실패했습니다.");
             }
             return true;
-        } catch (DataAccessException dae) {
-            throw dae;
         } catch (Exception e) {
             throw e;
         }
src/main/resources/message/messages_en.yml
--- src/main/resources/message/messages_en.yml
+++ src/main/resources/message/messages_en.yml
@@ -57,4 +57,12 @@
 
 # 파일 관련
 file:
-  upload_fail: "File upload failed."
(파일 끝에 줄바꿈 문자 없음)
+  upload_fail: "File upload failed."
+
+# 이메일 인증 관련
+email:
+  send_fail: "Failed to send email."
+  verify_success: "Email verification completed successfully."
+  verify_expired: "Email verification has expired."
+  verify_fail: "Email verification failed."
+  code_not_match: "verification code does not match."
(파일 끝에 줄바꿈 문자 없음)
Add a comment
List