Skip to content

Commit

Permalink
Merge pull request chaniii999#6 from deer0123/release
Browse files Browse the repository at this point in the history
email 관련 controller & method 삭제
  • Loading branch information
chaniii999 authored Nov 27, 2024
2 parents 3c3c9bc + 0b3e16f commit 76a92be
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/re_book/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// .requestMatchers("/user/list").hasAnyRole("ADMIN")
.requestMatchers("/board/list", "/sign-in",
"/sign-up", "/board/detail/*","/",
"check-email","/send-auth-code","/verify-auth-code").permitAll()
"/send-auth-code").permitAll()
.anyRequest().authenticated();
})
// 커스텀 필터를 등록.
Expand Down

This file was deleted.

24 changes: 10 additions & 14 deletions src/main/java/com/re_book/user/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,21 @@ public ResponseEntity<?> signUp(@RequestBody MemberRequestDTO dto) {

// 이메일 인증 코드 전송 처리
@PostMapping("/send-auth-code")
public ResponseEntity<?> sendAuthCode(@RequestParam String email, HttpSession session) throws MessagingException {
public ResponseEntity<?> sendAuthCode(@RequestBody Map<String, String> param) throws MessagingException {
String email = param.get("email");
email = email.trim();
boolean validEmail =email.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$");
boolean validEmail = email.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$");

if (validEmail) {
String authCode = memberService.sendAuthCode(email); // 인증 코드 발송
session.setAttribute("sentAuthCode", authCode); // 세션에 인증 코드 저장
return ResponseEntity.ok().body("인증번호 전송 성공."); // 성공 응답 반환
}
return ResponseEntity.badRequest().body("인증번호 전송 실패"); // 성공 응답 반환
Map<String, Object> logInfo = new HashMap<>();
logInfo.put("authCode", authCode);

}
CommonResDto resDto = new CommonResDto(HttpStatus.OK, "인증번호 전송 성공", logInfo);

// 인증 코드 확인 처리
@PostMapping("/verify-auth-code")
public ResponseEntity<Map<String, Object>> verifyAuthCode(@RequestParam String authCode, HttpSession session) {
String sentAuthCode = (String) session.getAttribute("sentAuthCode");
return new ResponseEntity<>(resDto, HttpStatus.OK);
}
return ResponseEntity.badRequest().body("인증번호 전송 실패"); // 성공 응답 반환

Map<String, Object> response = new HashMap<>();
response.put("isValid", sentAuthCode != null && sentAuthCode.equals(authCode)); // 입력된 코드와 비교
return ResponseEntity.ok(response); // 응답 반환
}
}

0 comments on commit 76a92be

Please sign in to comment.