diff --git a/src/main/java/com/example/sharemind/auth/application/AuthService.java b/src/main/java/com/example/sharemind/auth/application/AuthService.java index c8158de0..f4e65dd8 100644 --- a/src/main/java/com/example/sharemind/auth/application/AuthService.java +++ b/src/main/java/com/example/sharemind/auth/application/AuthService.java @@ -12,6 +12,8 @@ public interface AuthService { void checkDuplicateEmail(String email); + Boolean checkDuplicateRecoveryEmail(String email); + Boolean getPasswordMatched(AuthGetPasswordMatchRequest authGetPasswordMatchRequest, Long customerId); void updatePassword(AuthUpdatePasswordRequest authUpdatePasswordRequest, Long customerId); diff --git a/src/main/java/com/example/sharemind/auth/application/AuthServiceImpl.java b/src/main/java/com/example/sharemind/auth/application/AuthServiceImpl.java index d1a4b6d2..9ad995da 100644 --- a/src/main/java/com/example/sharemind/auth/application/AuthServiceImpl.java +++ b/src/main/java/com/example/sharemind/auth/application/AuthServiceImpl.java @@ -43,8 +43,12 @@ public class AuthServiceImpl implements AuthService { @Transactional @Override public void signUp(AuthSignUpRequest authSignUpRequest) { - if (customerRepository.existsByEmailAndIsActivatedIsTrue(authSignUpRequest.getEmail()) || customerRepository.existsByEmailAndIsActivatedIsTrue(authSignUpRequest.getRecoveryEmail())) { + if (customerRepository.existsByEmailAndIsActivatedIsTrue(authSignUpRequest.getEmail())) { throw new AuthException(AuthErrorCode.EMAIL_ALREADY_EXIST, authSignUpRequest.getEmail()); + } else if (customerRepository.existsByRecoveryEmailAndIsActivatedIsTrue( + authSignUpRequest.getRecoveryEmail())) { + throw new AuthException(AuthErrorCode.RECOVERY_EMAIL_ALREADY_EXIST, + authSignUpRequest.getRecoveryEmail()); } Customer customer = authSignUpRequest.toEntity(passwordEncoder.encode(authSignUpRequest.getPassword())); @@ -89,6 +93,11 @@ public void checkDuplicateEmail(String email) { } } + @Override + public Boolean checkDuplicateRecoveryEmail(String email) { + return customerRepository.existsByRecoveryEmailAndIsActivatedIsTrue(email); + } + @Override public Boolean getPasswordMatched(AuthGetPasswordMatchRequest authGetPasswordMatchRequest, Long customerId) { Customer customer = customerRepository.findByCustomerIdAndIsActivatedIsTrue(customerId) diff --git a/src/main/java/com/example/sharemind/auth/exception/AuthErrorCode.java b/src/main/java/com/example/sharemind/auth/exception/AuthErrorCode.java index b8994bdf..41b00899 100644 --- a/src/main/java/com/example/sharemind/auth/exception/AuthErrorCode.java +++ b/src/main/java/com/example/sharemind/auth/exception/AuthErrorCode.java @@ -6,7 +6,8 @@ @Getter public enum AuthErrorCode { - EMAIL_ALREADY_EXIST(HttpStatus.BAD_REQUEST, "이미 회원으로 등록된 이메일입니다."), + EMAIL_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 회원으로 등록된 이메일입니다."), + RECOVERY_EMAIL_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 등록된 복구 이메일입니다."), INVALID_RECOVERY_EMAIL(HttpStatus.BAD_REQUEST, "로그인 이메일과 동일한 이메일은 복구 이메일로 사용할 수 없습니다."), INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "비밀번호가 일치하지 않습니다."), DUPLICATE_PASSWORD(HttpStatus.BAD_REQUEST, "새 비밀번호가 현재 비밀번호와 동일합니다."), diff --git a/src/main/java/com/example/sharemind/auth/presentation/AuthController.java b/src/main/java/com/example/sharemind/auth/presentation/AuthController.java index 79c6109a..866ca065 100644 --- a/src/main/java/com/example/sharemind/auth/presentation/AuthController.java +++ b/src/main/java/com/example/sharemind/auth/presentation/AuthController.java @@ -29,7 +29,11 @@ public class AuthController { @Operation(summary = "회원가입", description = "customer 생성") @ApiResponses({ @ApiResponse(responseCode = "201", description = "회원가입 성공"), - @ApiResponse(responseCode = "400", description = "1. 이미 가입된 이메일 주소\n 2. 올바르지 않은 이메일/비밀번호/전화번호 형식\n 3. 로그인 이메일과 복구 이메일 주소가 동일", + @ApiResponse(responseCode = "400", description = "1. 올바르지 않은 이메일/비밀번호/전화번호 형식\n 2. 로그인 이메일과 복구 이메일 주소가 동일", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = CustomExceptionResponse.class)) + ), + @ApiResponse(responseCode = "409", description = "1. 이미 가입된 이메일 주소\n 2. 이미 등록된 복구 이메일 주소", content = @Content(mediaType = "application/json", schema = @Schema(implementation = CustomExceptionResponse.class)) ) @@ -148,7 +152,7 @@ public ResponseEntity signOut(@Valid @RequestBody AuthSignOutRequest authS schema = @Schema(implementation = CustomExceptionResponse.class)) ) }) - @PatchMapping("find-id") + @PatchMapping("/find-id") public ResponseEntity findIdByRecoveryEmail(@Valid @RequestBody AuthFindRequest authFindRequest) { authService.sendIdByRecoveryEmail(authFindRequest); return ResponseEntity.ok().build(); @@ -167,9 +171,22 @@ public ResponseEntity findIdByRecoveryEmail(@Valid @RequestBody AuthFindRe schema = @Schema(implementation = CustomExceptionResponse.class)) ) }) - @PatchMapping("find-password") + @PatchMapping("/find-password") public ResponseEntity findPasswordByRecoveryEmail(@Valid @RequestBody AuthFindRequest authFindRequest) { authService.updateAndSendPasswordByRecoveryEmail(authFindRequest); return ResponseEntity.ok().build(); } + + @Operation(summary = "복구 이메일 중복 확인", + description = """ + - 복구 이메일 중복 확인 + - 중복된 이메일 있으면 true, 없으면 false + - 주소 형식: /api/v1/auth/recovery-email?email=aaa@gmail.com""") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "확인 성공") + }) + @GetMapping("/recovery-email") + public ResponseEntity checkDuplicateRecoveryEmail(@RequestParam String email) { + return ResponseEntity.ok(authService.checkDuplicateRecoveryEmail(email)); + } } diff --git a/src/main/java/com/example/sharemind/customer/repository/CustomerRepository.java b/src/main/java/com/example/sharemind/customer/repository/CustomerRepository.java index 471bf82f..6c358e57 100644 --- a/src/main/java/com/example/sharemind/customer/repository/CustomerRepository.java +++ b/src/main/java/com/example/sharemind/customer/repository/CustomerRepository.java @@ -11,6 +11,8 @@ public interface CustomerRepository extends JpaRepository { Boolean existsByEmailAndIsActivatedIsTrue(String email); + Boolean existsByRecoveryEmailAndIsActivatedIsTrue(String recoveryEmail); + Optional findByEmailAndIsActivatedIsTrue(String email); Optional findByCustomerIdAndIsActivatedIsTrue(Long id); diff --git a/src/main/java/com/example/sharemind/global/config/SecurityConfig.java b/src/main/java/com/example/sharemind/global/config/SecurityConfig.java index 7532c742..0b7e8dc8 100644 --- a/src/main/java/com/example/sharemind/global/config/SecurityConfig.java +++ b/src/main/java/com/example/sharemind/global/config/SecurityConfig.java @@ -50,7 +50,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .authorizeHttpRequests( // TODO 여기 더 나은 방법이 있을 것 같은데 일단 동작은 하니까 두고 추후에 리팩토링...ㅠㅠ requests -> requests.requestMatchers("/error", "/swagger-ui/**", "/api-docs/**", "/api/v1/auth/signUp", "/api/v1/auth/signIn", "/api/v1/auth/reissue", - "/api/v1/auth/find-id", "/api/v1/auth/find-password", "/api/v1/emails/**").permitAll() + "/api/v1/auth/find-id", "/api/v1/auth/find-password", "/api/v1/auth/recovery-email/**", "/api/v1/emails/**").permitAll() .requestMatchers("/api/v1/counselors/all/**", "/api/v1/searchWords/results", "/api/v1/reviews/all/**").permitAll() .requestMatchers("/index.html", "/favicon.ico", "/chat/**", "/customer.html", "/counselor.html").permitAll()