From dcfa38a493d91d2f37c8de761c4d686862811333 Mon Sep 17 00:00:00 2001 From: kuhi Date: Tue, 16 Apr 2024 12:06:40 +0900 Subject: [PATCH] =?UTF-8?q?PH-110=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8?= =?UTF-8?q?=20=EC=9E=AC=EC=84=A4=EC=A0=95=EC=8B=9C=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/AccountController.java | 25 +++++++++++++++++-- .../api/common/service/AccountService.java | 5 ++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/module-api/src/main/java/com/peoplehere/api/common/controller/AccountController.java b/module-api/src/main/java/com/peoplehere/api/common/controller/AccountController.java index 2c4c9f7..d11ad3b 100644 --- a/module-api/src/main/java/com/peoplehere/api/common/controller/AccountController.java +++ b/module-api/src/main/java/com/peoplehere/api/common/controller/AccountController.java @@ -1,6 +1,7 @@ package com.peoplehere.api.common.controller; import static com.peoplehere.shared.common.util.PatternUtils.*; +import static org.springframework.http.HttpStatus.*; import java.security.Principal; @@ -23,6 +24,7 @@ import com.peoplehere.api.common.data.request.MailVerifyRequestDto; import com.peoplehere.api.common.data.response.MailVerificationResponseDto; import com.peoplehere.api.common.exception.ClientBindException; +import com.peoplehere.api.common.exception.DuplicateException; import com.peoplehere.api.common.service.AccountService; import com.peoplehere.api.common.service.VerifyService; import com.peoplehere.shared.common.data.request.AlarmConsentRequestDto; @@ -109,15 +111,34 @@ public ResponseEntity modifyPassword(@Validated @RequestBody PasswordReq * @return */ @GetMapping("/email/check") - public ResponseEntity checkEmail(@RequestParam String email) { + public ResponseEntity checkEmailDuplicate(@RequestParam String email) { if (!EMAIL_PATTERN.matcher(email).matches()) { log.error("이메일 형식 오류: {}", email); return ResponseEntity.badRequest().build(); } - accountService.checkEmail(email); + if (accountService.checkEmailExist(email)) { + throw new DuplicateException(email); + } return ResponseEntity.ok().body("success"); } + /** + * 비밀번호 재설정을 위한 이메일 유효성(db에 존재하는지) 체크 + * @param email 이메일 + * @return + */ + @GetMapping("/email/exist") + public ResponseEntity checkEmailExist(@RequestParam String email) { + if (!EMAIL_PATTERN.matcher(email).matches()) { + log.error("이메일 형식 오류: {}", email); + return ResponseEntity.badRequest().build(); + } + if (accountService.checkEmailExist(email)) { + return ResponseEntity.ok().body("success"); + } + return ResponseEntity.status(NOT_FOUND).body("해당 이메일: [%s]이 존재하지 않습니다".formatted(email)); + } + /** * 알람 동의 여부를 저장함 * @param requestDto 알람 동의 여부 diff --git a/module-api/src/main/java/com/peoplehere/api/common/service/AccountService.java b/module-api/src/main/java/com/peoplehere/api/common/service/AccountService.java index 5fd4349..50f4a0d 100644 --- a/module-api/src/main/java/com/peoplehere/api/common/service/AccountService.java +++ b/module-api/src/main/java/com/peoplehere/api/common/service/AccountService.java @@ -73,10 +73,11 @@ public void updatePassword(PasswordRequestDto requestDto) { } @Transactional(readOnly = true) - public void checkEmail(String email) { + public boolean checkEmailExist(String email) { if (accountRepository.existsByEmail(email)) { - throw new DuplicateException(email); + return true; } + return false; } @Transactional