-
Notifications
You must be signed in to change notification settings - Fork 3
feat: 이메일 인증 코드 검증 후 리디렉션 기능 추가 #208
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,15 @@ | ||
| package org.ezcode.codetest.presentation.usermanagement; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.ezcode.codetest.application.usermanagement.auth.dto.request.FindPasswordRequest; | ||
| import org.ezcode.codetest.application.usermanagement.user.dto.request.ResetPasswordRequest; | ||
| import org.ezcode.codetest.application.usermanagement.auth.dto.request.SendEmailRequest; | ||
| import org.ezcode.codetest.application.usermanagement.auth.dto.response.FindPasswordResponse; | ||
| import org.ezcode.codetest.application.usermanagement.auth.dto.response.SendEmailResponse; | ||
| import org.ezcode.codetest.application.usermanagement.auth.dto.response.VerifyEmailCodeResponse; | ||
| import org.ezcode.codetest.application.usermanagement.auth.service.AuthService; | ||
| import org.ezcode.codetest.application.usermanagement.user.dto.response.ChangeUserPasswordResponse; | ||
| import org.ezcode.codetest.application.usermanagement.user.dto.response.VerifyFindPasswordResponse; | ||
| import org.ezcode.codetest.domain.user.model.entity.AuthUser; | ||
| import org.ezcode.codetest.domain.user.exception.UserException; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
|
|
@@ -21,13 +19,19 @@ | |
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.util.UriComponentsBuilder; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URLEncoder; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
|
|
@@ -48,11 +52,34 @@ public ResponseEntity<SendEmailResponse> sendMailCode( | |
| //이메일에서 버튼 클릭하면 자동으로 연결 | ||
| @Operation(summary = "이메일 코드 입력 및 인증", description = "이메일로 받은 코드를 입력하여 이메일 인증된 회원으로 전환합니다") | ||
| @GetMapping("/auth/verify") | ||
| public ResponseEntity<VerifyEmailCodeResponse> verifyEmailCode( | ||
| public void verifyEmailCode( | ||
| @RequestParam String email, | ||
| @RequestParam String key | ||
| ){ | ||
| return ResponseEntity.status(HttpStatus.OK).body(authService.verifyEmailCode(email, key)); | ||
| @RequestParam String key, | ||
| HttpServletResponse response | ||
| ) throws IOException { | ||
| try { | ||
| authService.verifyEmailCode(email, key); | ||
|
|
||
| // 성공 시 프론트엔드로 리디렉션 | ||
| String redirectUrl = UriComponentsBuilder | ||
| .fromUriString("https://ezcode.my/email-verify-success") | ||
| .queryParam("status", "success") | ||
| .build() | ||
| .toUriString(); | ||
|
|
||
| response.sendRedirect(redirectUrl); | ||
| } catch (UserException e) { | ||
| // 실패 시 프론트엔드로 리디렉션 (에러 메시지 포함) | ||
| String errorMessage = URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8); | ||
| String redirectUrl = UriComponentsBuilder | ||
| .fromUriString("https://ezcode.my/email-verify-failure") | ||
| .queryParam("status", "failure") | ||
| .queryParam("message", errorMessage) | ||
| .build() | ||
| .toUriString(); | ||
|
Comment on lines
+73
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. URL 이중 인코딩 문제가 발생할 수 있습니다.
🐛 수정 제안- String errorMessage = URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8);
String redirectUrl = UriComponentsBuilder
.fromUriString("https://ezcode.my/email-verify-failure")
.queryParam("status", "failure")
- .queryParam("message", errorMessage)
- .build()
+ .queryParam("message", e.getMessage())
+ .encode()
+ .build()
.toUriString();
🤖 Prompt for AI Agents |
||
|
|
||
| response.sendRedirect(redirectUrl); | ||
| } | ||
|
Comment on lines
+71
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🐛 예외 처리 보완 예시 } catch (UserException e) {
// 실패 시 프론트엔드로 리디렉션 (에러 메시지 포함)
- String errorMessage = URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8);
String redirectUrl = UriComponentsBuilder
.fromUriString("https://ezcode.my/email-verify-failure")
.queryParam("status", "failure")
- .queryParam("message", errorMessage)
- .build()
+ .queryParam("message", e.getMessage())
+ .encode()
+ .build()
.toUriString();
response.sendRedirect(redirectUrl);
+ } catch (Exception e) {
+ log.error("이메일 인증 중 예외 발생: email={}", email, e);
+ String redirectUrl = UriComponentsBuilder
+ .fromUriString("https://ezcode.my/email-verify-failure")
+ .queryParam("status", "failure")
+ .queryParam("message", "인증 처리 중 오류가 발생했습니다.")
+ .encode()
+ .build()
+ .toUriString();
+
+ response.sendRedirect(redirectUrl);
}🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
하드코딩된 리디렉션 URL을 설정으로 분리하세요.
https://ezcode.my/...URL이 하드코딩되어 있습니다. 개발/스테이징/프로덕션 환경에 따라 다른 URL을 사용해야 할 가능성이 높으므로,application.yml또는@Value를 통해 외부 설정으로 분리하는 것이 좋습니다.♻️ 설정 분리 예시
🤖 Prompt for AI Agents