Skip to content

Commit

Permalink
Merge pull request #79 from backendoori/feature-email-redis-ttl
Browse files Browse the repository at this point in the history
🚀 Redis TTL 설정을 통한 이메일 인증 만료 기능 추가
  • Loading branch information
Sehee-Lee-01 authored Jan 18, 2024
2 parents 09ffbcc + f5640ed commit 48ffb69
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@Getter
@Builder
@RedisHash("certificate")
@RedisHash(value = "certificate", timeToLive = 10 * 60L)
public class Certificate {

public static final int SIZE = 6;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.backendoori.ootw.user.exception;

public class ExpiredCertificateException extends IllegalArgumentException {

public static final String DEFAULT_MESSAGE = "만료된 인증 코드 입니다.";

public ExpiredCertificateException() {
super(DEFAULT_MESSAGE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.backendoori.ootw.user.dto.CertifyDto;
import com.backendoori.ootw.user.dto.SendCodeDto;
import com.backendoori.ootw.user.exception.AlreadyCertifiedUserException;
import com.backendoori.ootw.user.exception.ExpiredCertificateException;
import com.backendoori.ootw.user.exception.IncorrectCertificateException;
import com.backendoori.ootw.user.repository.CertificateRedisRepository;
import com.backendoori.ootw.user.repository.UserRepository;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void certify(CertifyDto certifyDto) {
AssertUtil.throwIf(user.isCertified(), AlreadyCertifiedUserException::new);

Certificate certificate = certificateRedisRepository.findById(certifyDto.email())
.orElseThrow(UserNotFoundException::new);
.orElseThrow(ExpiredCertificateException::new);
boolean isIncorrectCertificate = !certifyDto.code().equals(certificate.getCode());

AssertUtil.throwIf(isIncorrectCertificate, IncorrectCertificateException::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.backendoori.ootw.user.dto.CertifyDto;
import com.backendoori.ootw.user.dto.SendCodeDto;
import com.backendoori.ootw.user.exception.AlreadyCertifiedUserException;
import com.backendoori.ootw.user.exception.ExpiredCertificateException;
import com.backendoori.ootw.user.exception.IncorrectCertificateException;
import com.backendoori.ootw.user.repository.CertificateRedisRepository;
import com.backendoori.ootw.user.repository.UserRepository;
Expand Down Expand Up @@ -173,7 +174,7 @@ void failCertificateNotFound() {
ThrowingCallable certify = () -> certificateService.certify(certifyDto);

// then
assertThatExceptionOfType(UserNotFoundException.class)
assertThatExceptionOfType(ExpiredCertificateException.class)
.isThrownBy(certify);
}

Expand Down

0 comments on commit 48ffb69

Please sign in to comment.