From 72ae8eded8d86a1381a96979d848141424de365f Mon Sep 17 00:00:00 2001 From: chaeyoungeee Date: Wed, 31 Jul 2024 01:13:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A9=94=EC=9D=BC/=EB=8B=89?= =?UTF-8?q?=EB=84=A4=EC=9E=84=20=EC=A4=91=EB=B3=B5=20=EC=A0=90=EA=B2=80=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 회원가입 시 한 번에 점검하던 이메일, 닉네임 중복 점검을 각각 이메일 점검 api, 닉네임 점검 api로 분리함 --- .../MZConnent/api/member/LoginController.java | 16 ++++++++-- .../MZConnent/config/SecurityConfig.java | 2 +- .../service/member/LoginService.java | 29 +++++++++++-------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/main/java/likelion/MZConnent/api/member/LoginController.java b/src/main/java/likelion/MZConnent/api/member/LoginController.java index 3efe560..aa84660 100644 --- a/src/main/java/likelion/MZConnent/api/member/LoginController.java +++ b/src/main/java/likelion/MZConnent/api/member/LoginController.java @@ -33,7 +33,7 @@ public ResponseEntity register(@Valid @RequestBody CreateMemberRequest request, Long memberId = loginService.createUser(request); log.info("회원가입 성공: {}", memberId); - return ResponseEntity.ok("회원가입 성공"); + return ResponseEntity.ok(Map.of("message", "회원가입 성공")); } @PostMapping("/api/auth/login") @@ -50,7 +50,7 @@ public ResponseEntity login(@Valid @RequestBody LoginMemberRequest request, Bind } @PostMapping("/api/auth/logout") - public ResponseEntity logout(@AuthenticationPrincipal UserPrinciple userPrinciple, @RequestHeader("Authorization") String authHeader) { + public ResponseEntity> logout(@AuthenticationPrincipal UserPrinciple userPrinciple, @RequestHeader("Authorization") String authHeader) { String email = userPrinciple.getEmail(); log.info("로그아웃 이메일: {}", email); @@ -60,4 +60,16 @@ public ResponseEntity logout(@AuthenticationPrincipal UserPrinciple userPrincipl return ResponseEntity.ok(Map.of("message", "로그아웃 성공")); } + + @GetMapping("/api/auth/email") + public ResponseEntity> checkDuplicateEmail(@RequestParam("email") String email) { + loginService.checkDuplicateEmail(email); + return ResponseEntity.ok(Map.of("message", "이메일 중복 점검 성공")); + } + + @GetMapping("/api/auth/username") + public ResponseEntity> checkDuplicateUsername(@RequestParam("username") String username) { + loginService.checkDuplicateUsername(username); + return ResponseEntity.ok(Map.of("message", "닉네임 중복 점검 성공")); + } } diff --git a/src/main/java/likelion/MZConnent/config/SecurityConfig.java b/src/main/java/likelion/MZConnent/config/SecurityConfig.java index 0aba1ad..96e98e8 100644 --- a/src/main/java/likelion/MZConnent/config/SecurityConfig.java +++ b/src/main/java/likelion/MZConnent/config/SecurityConfig.java @@ -44,7 +44,7 @@ public class SecurityConfig { // 아무나 접근 가능한 URI private final String[] permitAllUrl = {"/error", - "/api/auth/login", // 회원 + "/api/auth/login", "/api/auth/email", "/api/auth/username", // 회원 "/api/categories/culture", "/api/cultures", "/api/cultures/**", // 문화 "/api/reviews", // 후기 "/api/categories/region", "/api/clubs/list", diff --git a/src/main/java/likelion/MZConnent/service/member/LoginService.java b/src/main/java/likelion/MZConnent/service/member/LoginService.java index 379622f..8286e20 100644 --- a/src/main/java/likelion/MZConnent/service/member/LoginService.java +++ b/src/main/java/likelion/MZConnent/service/member/LoginService.java @@ -45,18 +45,6 @@ public Long createUser(CreateMemberRequest request) { // 비밀번호 정책에 맞는지 점검 checkPasswordPolicy(request.getPassword()); - // 이미 등록된 이메일인지 점검 - if (memberRepository.existsByEmail(request.getEmail())) { - log.info("이미 등록된 이메일={}", request.getEmail()); - throw new IllegalArgumentException("이미 등록된 이메일입니다."); - } - - // 중복되는 닉네임인지 점검 - if (memberRepository.existsByUsername(request.getUsername())) { - log.info("중복되는 닉네임={}", request.getEmail()); - throw new IllegalArgumentException("중복되는 닉네임입니다."); - } - Member member = Member.builder() .email(request.getEmail()) .password(passwordEncoder.encode(request.getPassword())) // 비밀번호 암호화 @@ -121,6 +109,22 @@ public void logoout(String accessToken, String email) { accessTokenBlackList.setBlackList(accessToken, email); } + // 이메일 중복 점검 + public void checkDuplicateEmail(String email) { + if (memberRepository.existsByEmail(email)) { + log.info("이미 등록된 이메일={}", email); + throw new IllegalArgumentException("이미 등록된 이메일입니다."); + } + } + + // 닉네임 중복 점검 + public void checkDuplicateUsername(String username) { + if (memberRepository.existsByUsername(username)) { + log.info("중복되는 닉네임={}", username); + throw new IllegalArgumentException("중복되는 닉네임입니다."); + } + } + // 비밀번호 정책에 맞는지 점검하는 함수 private void checkPasswordPolicy(String password) { @@ -146,4 +150,5 @@ private void checkPassword(String password, Member member) { } } + }