Skip to content

Commit d11358a

Browse files
authored
Merge pull request #140 from Money-Touch/feat/#57
2 parents 11b1159 + a473b71 commit d11358a

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

src/main/java/com/server/money_touch/domain/user/controller/UserController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public ApiResponse<UserResponse.UserDetailCreateResultDTO> createUserDetail(
6666
@ApiErrorCodeExample(value = ErrorStatus.class, name = "_INTERNAL_SERVER_ERROR")
6767
})
6868
@GetMapping("/email/send")
69-
public ApiResponse<String> requestEmail(@RequestParam("to") String toEmail) {
69+
public ApiResponse<String> requestEmail(@RequestParam("to") String toEmail, @RequestParam boolean isResend) {
7070
try {
71-
userQueryService.requestEmailVerification(toEmail);
71+
userQueryService.requestEmailVerification(toEmail, isResend);
7272
return ApiResponse.onSuccess("인증 이메일이 발송되었습니다.");
7373
} catch (IOException e) {
7474
// 로그 기록 추가 가능

src/main/java/com/server/money_touch/domain/user/service/user/AuthService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
import com.server.money_touch.domain.budget.enums.CategoryType;
55
import com.server.money_touch.domain.budget.service.budget.BudgetCommandService;
66
import com.server.money_touch.domain.consumptionRecord.converter.totalConsumption.TotalConsumptionConverter;
7-
import com.server.money_touch.domain.consumptionRecord.entity.TotalConsumption;
87
import com.server.money_touch.domain.consumptionRecord.repository.totalConsumption.TotalConsumptionRepository;
9-
import com.server.money_touch.domain.user.converter.AuthConverter;
10-
import com.server.money_touch.domain.user.converter.UserConverter;
118
import com.server.money_touch.domain.user.dto.KakaoDTO;
129
import com.server.money_touch.domain.user.dto.TokenResponse;
1310
import com.server.money_touch.domain.user.dto.UserResponse;
@@ -96,9 +93,11 @@ public UserResponse.OAuthLoginResultDTO oAuthLogin(String accessCode, String red
9693
public User createNewUser(KakaoDTO.KakaoProfile kakaoProfile) {
9794
String email = kakaoProfile.getKakaoAccount().getEmail();
9895
String kakaoKey = String.valueOf(kakaoProfile.getId());
96+
String nickname = kakaoProfile.getKakaoAccount().getProfile().getNickname();
9997

10098
// 1. User 생성
10199
User newUser = User.builder()
100+
.nickname(nickname)
102101
.email(email)
103102
.authType(AuthType.KAKAO)
104103
.role(Role.USER)

src/main/java/com/server/money_touch/domain/user/service/user/UserQueryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface UserQueryService {
1515
Boolean existsByNickname(String nickname);
1616

1717
// 이메일 요청및 이메일 중복 검증
18-
void requestEmailVerification(String toEmail)throws IOException;
18+
void requestEmailVerification(String toEmail, boolean isResend)throws IOException;
1919

2020
// 마이페이지 유저 정보 조회
2121
UserResponse.MyPageResponseDTO getMyPageInfo(Long userId);

src/main/java/com/server/money_touch/domain/user/service/user/UserQueryServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public Boolean existsByNickname(String nickname) {
4444
}
4545

4646
// 이메일 인증번호 발송
47-
public void requestEmailVerification(String toEmail) throws IOException {
47+
public void requestEmailVerification(String toEmail, boolean isResend) throws IOException {
4848
// 이메일 중복 체크
4949
if (existsByEmail(toEmail)) {
5050
throw new IllegalArgumentException("이미 가입된 이메일입니다.");
5151
}
5252

5353
// 이메일 발송
54-
sendGridUtil.sendEmail(toEmail);
54+
sendGridUtil.sendEmail(toEmail, isResend);
5555
}
5656

5757
// 마이페이지

src/main/java/com/server/money_touch/global/config/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
3030
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // 세션 STATELESS 상태로 설정
3131
.authorizeHttpRequests((requests) -> requests
3232
.requestMatchers(
33-
"/api/user/signup/local", "/api/user/login/local","/auth/login/kakao/**", "/api/user/nickname", "/api/user/email/send","/api/user/email/verify", "/api/consumptionMbti/save", // 로그인, 회원가입, 이메일 요청, 닉네임 중복 확인
33+
"/api/user/signup/local", "/api/user/login/local","/auth/login/kakao/**", "/api/user/nickname", "/api/user/email/send","/api/user/email/verify", "/api/consumptionMbti/save", "/api/user/delete", // 로그인, 회원가입, 이메일 요청, 닉네임 중복 확인
3434
"/", "/index.html", "/css/**", "/js/**", "/images/**", "/actuator/health", // Spring Boot의 정적 리소스 기본 경로 및 test
3535
"/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui.html", // Swaggger 문서
3636
"/api/test/s3/upload") // 프로필 이미지 업로드

src/main/java/com/server/money_touch/global/utils/SendGridUtil.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,32 @@ public String generateAuthCode() {
3434
}
3535

3636

37-
public void sendEmail(String toEmail) throws IOException {
37+
public void sendEmail(String toEmail, boolean isResend) throws IOException {
3838

39-
// 보내는 사람 (발신자)
40-
Email from = new Email(fromEmail);
41-
// 제목
42-
String subject = "💸돈터치 이메일 발송 안내";
43-
// 받는 사람 (수신자)
44-
Email to = new Email(toEmail);
39+
String redisKey = "emailAuth:" + toEmail;
40+
41+
// 재전송이면 기존 인증번호 삭제
42+
if (isResend && redisTemplate.hasKey(redisKey)) {
43+
redisTemplate.delete(redisKey);
44+
log.info("♻ 기존 인증번호 삭제 완료 - key: {}", redisKey);
45+
}
4546

4647
// 인증번호 생성
4748
String authCode = generateAuthCode();
4849

49-
// Redis에 저장 (5분 TTL)
50-
String redisKey = "emailAuth:" + toEmail;
51-
redisTemplate.opsForValue().set(redisKey, authCode, 5, TimeUnit.MINUTES);
52-
53-
// 로그 출력 (인증코드 저장 확인)
54-
String savedCode = redisTemplate.opsForValue().get(redisKey);
55-
log.info("✅ Redis 저장 완료 - key: {}, value: {}", redisKey, savedCode);
50+
// TTL 설정 (최초 발송 5분, 재발송 3분)
51+
long ttlMinutes = isResend ? 3 : 5;
52+
redisTemplate.opsForValue().set(redisKey, authCode, ttlMinutes, TimeUnit.MINUTES);
53+
log.info("✅ 인증번호 저장 완료 - key: {}, value: {}, TTL: {}분", redisKey, authCode, ttlMinutes);
5654

55+
// 메일 발송
56+
Email from = new Email(fromEmail);
57+
Email to = new Email(toEmail);
58+
String subject = isResend ? "💸 돈터치 이메일 인증번호 재전송 안내" : "💸 돈터치 이메일 발송 안내";
5759
Content content = new Content("text/plain", "인증번호: " + authCode);
5860
Mail mail = new Mail(from, subject, to, content);
5961

62+
6063
send(mail);
6164

6265

0 commit comments

Comments
 (0)