Skip to content

Commit

Permalink
feat: 이메일 인증 요청 url
Browse files Browse the repository at this point in the history
  • Loading branch information
tejava7177 committed Oct 19, 2024
1 parent 8998b70 commit 78e77ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
import com.sch.chekirout.email.service.EmailService;
import com.sch.chekirout.user.application.UserService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.net.URI;

@RestController
@RequestMapping("/api/v1/auth")
public class EmailController {
Expand All @@ -31,9 +37,14 @@ public ResponseEntity<String> verifyEmail(@RequestParam("token") String token) {
boolean isVerified = emailService.verifyEmail(token);

if (isVerified) {
return ResponseEntity.ok("이메일 인증이 완료되었습니다. 회원가입을 진행해주세요!!");
// 인증 성공 시 리다이렉트
HttpHeaders headers = new HttpHeaders();
headers.setLocation(URI.create("https://dev.chekirout.com/email/verifyToken"));
return new ResponseEntity<>(headers, HttpStatus.FOUND); // 302 리다이렉트
} else {
return ResponseEntity.badRequest().body("유효하지 않거나 만료된 인증 토큰입니다.");
// 인증 실패 시 적절한 에러 메시지와 400 Bad Request 반환
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body("유효하지 않거나 만료된 인증 토큰입니다.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void sendVerificationEmail(String recipientEmail) {
String token = generateEmailVerificationToken(recipientEmail);

String subject = "이메일 인증을 완료해주세요";
String verificationUrl = "http://dev.chekirout.com/api/v1/auth/verify-email?token=" + token;
String verificationUrl = "https://dev.chekirout.com/api/v1/auth/verify-email?token=" + token;
String message = "아래 링크를 클릭하여 이메일 인증을 완료하세요: <a href='" + verificationUrl + "'>인증 링크</a>";

try {
Expand All @@ -44,7 +44,7 @@ public void sendVerificationEmail(String recipientEmail) {
helper.setTo(recipientEmail); // 수신자 이메일 설정
helper.setSubject(subject); // 이메일 제목 설정
helper.setText(message, true); // HTML 형식으로 본문 설정
helper.setFrom("chekirout <juheun9912@gamil.com>");
helper.setFrom("chekirout <juheun9912@gmail.com>");

mailSender.send(email); // 이메일 전송
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/chekirout
username: root
password: rlawjdgns10!
password: root1234
p6spy:
enabled: true
appender: com.p6spy.engine.spy.appender.Slf4JLogger
Expand Down

0 comments on commit 78e77ab

Please sign in to comment.