Skip to content

Commit

Permalink
feat/member-email-verify-2: 전송 보내고나서는 인증번호 자동으로 삭제되도록 (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
KooSuYeon authored Jan 15, 2025
1 parent 41a26a0 commit 1099c41
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/dife/api/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ public class MemberService {
private final RedisUtil redisUtil;

public void checkEmail(CheckEmailDto dto) {
String email = dto.getEmail();
String email = dto.getEmail().trim();

if (memberRepository.existsByEmail(email))
throw new DuplicateMemberException("이미 가입되어있는 이메일입니다");

String previousVerifyCode = redisUtil.getData(email);
if (previousVerifyCode != null) {
redisUtil.deleteData(email);
}

Random random = new Random();
String verifyCode = String.format("%04d", random.nextInt(10000));
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
Expand All @@ -93,12 +98,13 @@ public void checkEmail(CheckEmailDto dto) {
}

public void verifyEmail(String email, String verifyCode) {
String storedVerifyCode = redisUtil.getData(email);
String storedVerifyCode = redisUtil.getData(email.trim());
String trimmedVerifyCode = verifyCode.trim();

if (storedVerifyCode == null) {
throw new MemberNullException("인증번호가 만료되었거나 존재하지 않습니다.");
}
if (!storedVerifyCode.equals(verifyCode)) {
if (!storedVerifyCode.equals(trimmedVerifyCode)) {
throw new MemberNullException("인증번호가 일치하지 않습니다!");
}
}
Expand Down

0 comments on commit 1099c41

Please sign in to comment.