Skip to content

Commit 9300412

Browse files
committed
RINGUS-25 refactor: 정적 변수 값을 환경변수로 분리
1 parent 5871779 commit 9300412

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/main/java/es/princip/ringus/application/auth/service/EmailVerificationService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import es.princip.ringus.domain.exception.SignUpErrorCode;
99
import es.princip.ringus.domain.member.MemberRepository;
1010
import es.princip.ringus.global.exception.CustomRuntimeException;
11+
import jakarta.annotation.PostConstruct;
1112
import jakarta.servlet.http.HttpSession;
1213
import jakarta.transaction.Transactional;
1314
import lombok.RequiredArgsConstructor;
15+
import org.springframework.beans.factory.annotation.Value;
1416
import org.springframework.stereotype.Service;
1517

1618
import java.util.Objects;
@@ -24,6 +26,14 @@ public class EmailVerificationService {
2426
private final MemberRepository memberRepository;
2527
private final EmailSendService emailSendService;
2628

29+
@Value("${verification.max-failed-attempts}")
30+
private int maxFailedAttempts;
31+
32+
@PostConstruct
33+
public void init(){
34+
EmailVerification.setMaxFailedAttempts(maxFailedAttempts);
35+
}
36+
2737
@Transactional
2838
public void generateVerificationCode(String email) {
2939
if(memberRepository.existsByEmail(email)){

src/main/java/es/princip/ringus/domain/email/EmailVerification.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.NoArgsConstructor;
66
import org.springframework.data.annotation.Id;
77
import org.springframework.data.redis.core.RedisHash;
8+
89
import java.io.Serializable;
910
import java.util.Random;
1011

@@ -26,6 +27,8 @@ public class EmailVerification implements Serializable {
2627

2728
private int failedAttempts;
2829

30+
private static int maxFailedAttempts;
31+
2932
public static EmailVerification of(String email) {
3033
return new EmailVerification(email, generateVerificationCode());
3134
}
@@ -45,10 +48,14 @@ public void plusFailedAttempts() {
4548
}
4649

4750
public boolean hasVerificationAttemptsLeft() {
48-
return failedAttempts < 4;
51+
return failedAttempts < maxFailedAttempts;
4952
}
5053

5154
public boolean isValid(String inputCode) {
5255
return this.verificationCode.equals(inputCode);
5356
}
57+
58+
public static void setMaxFailedAttempts(int maxFailedAttempts) {
59+
EmailVerification.maxFailedAttempts = maxFailedAttempts;
60+
}
5461
}

src/main/java/es/princip/ringus/global/util/CookieUtil.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
import jakarta.servlet.http.Cookie;
44
import jakarta.servlet.http.HttpServletResponse;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.stereotype.Component;
57

68
/**
79
* 쿠키 관련 유틸리티 클래스
810
* - 쿠키 생성 및 삭제 기능 제공
911
* - 보안 설정 적용 (HttpOnly, Secure)
1012
*/
13+
14+
@Component
1115
public class CookieUtil {
1216

1317
/** 기본 쿠키 만료 시간 (30분) */
14-
private static final int DEFAULT_EXPIRY = 60 * 30; // 30 minutes
18+
private static int DEFAULT_EXPIRY;
19+
20+
public CookieUtil(@Value("${verification.default_expiry}") int DEFAULT_EXPIRY) {
21+
CookieUtil.DEFAULT_EXPIRY = DEFAULT_EXPIRY;
22+
}
1523

1624
/**
1725
* 쿠키를 생성하여 응답(Response)에 추가하는 메서드

src/main/resources/application.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ spring:
4040
university:
4141
file:
4242
path: ${UNIVERSITY_FILE_PATH}
43+
44+
verification:
45+
max_failed_attempts: ${MAX_FAILED_ATTEMPTS}
46+
default_expiry: ${DEFAULT_EXPIRY}

0 commit comments

Comments
 (0)