Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] 이메일 인증 과정 중 해당 유저의 회원가입 과정 진행 상태에 따른 response하는 StatusName 수정 & AES 복호화된 값을 BASE64 Decode 과정 추가 #83

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

import javax.transaction.Transactional;
import java.time.LocalDateTime;
import java.util.Optional;

@Repository
public interface EmailAuthRepository extends JpaRepository<EmailAuth, Long> {
boolean existsByEmail(String email);

EmailAuth findEmailAuthByEmail(String email);
// EmailAuth findEmailAuthByEmail(String email);

EmailAuth findEmailAuthByEmailAndAuthToken(String email, String authToken);

Expand All @@ -23,6 +24,6 @@ public interface EmailAuthRepository extends JpaRepository<EmailAuth, Long> {
@Query("DELETE FROM EmailAuth e WHERE e.expireDate < :currentDateTime AND e.certification = false")
void deleteExpiredRecords(@Param("currentDateTime") LocalDateTime currentDateTime);


Optional<EmailAuth> findEmailAuthByEmail(String email);
}

23 changes: 19 additions & 4 deletions src/main/java/com/wooyeon/yeon/user/service/EmailAuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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<EmailAuth> 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 {
// 이메일 인증 링크 발송
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/wooyeon/yeon/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}