diff --git a/src/main/java/com/wooyeon/yeon/user/controller/UserController.java b/src/main/java/com/wooyeon/yeon/user/controller/UserController.java index 519724b..cc46778 100644 --- a/src/main/java/com/wooyeon/yeon/user/controller/UserController.java +++ b/src/main/java/com/wooyeon/yeon/user/controller/UserController.java @@ -48,7 +48,6 @@ public SseEmitter sendEmailVerify(@RequestBody EmailRequestDto emailRequestDto) try { emitter.send(SseEmitter.event().name("INIT").data("SSE Connected")); emitter.send(SseEmitter.event().data(emailResponseDto)); - log.debug("[Controller] emailResponseDto: {}", emailResponseDto); } catch (IOException e) { emitter.completeWithError(e); } diff --git a/src/main/java/com/wooyeon/yeon/user/repository/EmailAuthRepository.java b/src/main/java/com/wooyeon/yeon/user/repository/EmailAuthRepository.java index 449ad18..671b2ae 100644 --- a/src/main/java/com/wooyeon/yeon/user/repository/EmailAuthRepository.java +++ b/src/main/java/com/wooyeon/yeon/user/repository/EmailAuthRepository.java @@ -9,12 +9,13 @@ import javax.transaction.Transactional; import java.time.LocalDateTime; +import java.util.Optional; @Repository public interface EmailAuthRepository extends JpaRepository { boolean existsByEmail(String email); - EmailAuth findEmailAuthByEmail(String email); + // EmailAuth findEmailAuthByEmail(String email); EmailAuth findEmailAuthByEmailAndAuthToken(String email, String authToken); @@ -23,6 +24,6 @@ public interface EmailAuthRepository extends JpaRepository { @Query("DELETE FROM EmailAuth e WHERE e.expireDate < :currentDateTime AND e.certification = false") void deleteExpiredRecords(@Param("currentDateTime") LocalDateTime currentDateTime); - + Optional findEmailAuthByEmail(String email); } diff --git a/src/main/java/com/wooyeon/yeon/user/service/EmailAuthService.java b/src/main/java/com/wooyeon/yeon/user/service/EmailAuthService.java index 32e55a2..7668cf2 100644 --- a/src/main/java/com/wooyeon/yeon/user/service/EmailAuthService.java +++ b/src/main/java/com/wooyeon/yeon/user/service/EmailAuthService.java @@ -23,6 +23,7 @@ import javax.mail.internet.MimeMessage; import java.time.LocalDateTime; import java.util.Base64; +import java.util.Optional; import java.util.UUID; @PropertySource("classpath:application-apikey.properties") @@ -49,19 +50,33 @@ public EmailResponseDto sendEmail(EmailRequestDto emailRequestDto) throws Messag // 이메일 중복 확인 로직 추가 if (validateDuplicated(emailRequestDto.getEmail())) { - log.debug(emailRequestDto.getEmail()+" certification: {}", emailAuthRepository.findEmailAuthByEmail(emailRequestDto.getEmail()).isCertification()); - EmailResponseDto emailResponseDto = EmailResponseDto.builder() .statusCode(HttpStatus.SC_OK) // 오류코드 대신 200 부탁함 .email(emailRequestDto.getEmail()) .build(); - + /* + // 해당 이메일이 이미 인증된 이메일인지? if (emailAuthRepository.findEmailAuthByEmail(emailRequestDto.getEmail()).isCertification()) { + + if(userRepository.findByEmail(emailRequestDto.getEmail())!=null) { + emailResponseDto.updateStatusName("ExistsUser"); + } emailResponseDto.updateStatusName("completed"); } else { emailResponseDto.updateStatusName("duplicated"); } - log.debug("emailResponseDto 이미 있음 : {}", emailResponseDto); + */ + Optional emailAuthOptional = emailAuthRepository.findEmailAuthByEmail(emailRequestDto.getEmail()); + if (emailAuthOptional.isPresent() && emailAuthOptional.get().isCertification()) { + // 해당 이메일이 이미 인증된 경우 + if (userRepository.findByEmail(emailRequestDto.getEmail()) != null) { + emailResponseDto.updateStatusName("ExistsUser"); + } else { + emailResponseDto.updateStatusName("completed"); + } + } else { + emailResponseDto.updateStatusName("duplicated"); + } return emailResponseDto; } else { // 이메일 인증 링크 발송 diff --git a/src/main/java/com/wooyeon/yeon/user/service/UserService.java b/src/main/java/com/wooyeon/yeon/user/service/UserService.java index ce30299..29ee96a 100644 --- a/src/main/java/com/wooyeon/yeon/user/service/UserService.java +++ b/src/main/java/com/wooyeon/yeon/user/service/UserService.java @@ -85,11 +85,13 @@ public PasswordEncryptResponseDto decodeEncrypt(PasswordEncryptRequestDto passwo String decodedPassword = aesUtil.decrypt(passwordEncryptRequestDto.getEncryptedPassword(), decodedKey, ivBytes); log.debug("AES로 복호화한 원문 : {}", decodedPassword); -// 비밀번호 + salt를 SHA256으로 암호화 -// String salt = createSalt(); -// String password = decodedPassword+salt; -// log.info("salt : {}", salt); -// log.info("finalPassword : {}", finalPassword); + /* + 비밀번호 + salt를 SHA256으로 암호화 + String salt = createSalt(); + String password = decodedPassword+salt; + log.info("salt : {}", salt); + log.info("finalPassword : {}", finalPassword); + */ // passwordEncoder로 비밀번호 암호화 (2024.02.06 로그인과 암호화 방식 맞춤 수정) String finalPassword = passwordEncoder.encode(decodedPassword); diff --git a/src/main/java/com/wooyeon/yeon/user/service/encrypt/AesUtil.java b/src/main/java/com/wooyeon/yeon/user/service/encrypt/AesUtil.java index f1cd268..e21e0bd 100644 --- a/src/main/java/com/wooyeon/yeon/user/service/encrypt/AesUtil.java +++ b/src/main/java/com/wooyeon/yeon/user/service/encrypt/AesUtil.java @@ -29,7 +29,7 @@ public static String decrypt(String ciphertext, byte[] aesKeyBytes, byte[] ivByt // 복호화 수행 byte[] decryptedBytes = cipher.doFinal(encryptedBytes); - return new String(decryptedBytes, StandardCharsets.UTF_8); + return new String(Base64.getDecoder().decode(decryptedBytes), StandardCharsets.UTF_8); } } \ No newline at end of file