From ad1e6b7533454222dc1934dfe2176a61feb35761 Mon Sep 17 00:00:00 2001 From: junker Date: Sun, 20 Aug 2023 18:10:04 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Blocked=EB=90=9C=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=EA=B0=80=20=EC=A0=91=EC=86=8D=20=EC=8B=9C=20Exception?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/controller/AuthController.java | 9 ++++++--- .../domain/auth/exception/UserBlockedException.java | 13 +++++++++++++ .../server/domain/user/service/UserService.java | 8 ++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/sluv/server/domain/auth/exception/UserBlockedException.java diff --git a/src/main/java/com/sluv/server/domain/auth/controller/AuthController.java b/src/main/java/com/sluv/server/domain/auth/controller/AuthController.java index 8d0550a4..1dc8d25e 100644 --- a/src/main/java/com/sluv/server/domain/auth/controller/AuthController.java +++ b/src/main/java/com/sluv/server/domain/auth/controller/AuthController.java @@ -9,6 +9,8 @@ import com.sluv.server.domain.auth.service.KakaoUserService; import com.sluv.server.domain.user.dto.UserIdDto; +import com.sluv.server.domain.user.entity.User; +import com.sluv.server.domain.user.service.UserService; import com.sluv.server.global.common.response.ErrorResponse; import com.sluv.server.global.common.response.SuccessDataResponse; import com.sluv.server.global.common.response.SuccessResponse; @@ -24,6 +26,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @RestController @@ -35,6 +38,7 @@ public class AuthController { private final GoogleUserService googleUserService; private final AppleUserService appleUserService; private final AuthService authService; + private final UserService userService; private final JwtProvider jwtProvider; @@ -71,9 +75,8 @@ public ResponseEntity> socialLogin(@Request summary = "*자동 로그인" ) @GetMapping("/auto-login") - public ResponseEntity autoLogin(HttpServletRequest request){ - String accessToken = jwtProvider.resolveToken(request); - jwtProvider.validateToken(accessToken); + public ResponseEntity autoLogin(@AuthenticationPrincipal User user){ + userService.checkUserStatue(user); return ResponseEntity.ok().body(new SuccessResponse()); } diff --git a/src/main/java/com/sluv/server/domain/auth/exception/UserBlockedException.java b/src/main/java/com/sluv/server/domain/auth/exception/UserBlockedException.java new file mode 100644 index 00000000..1ad31ddf --- /dev/null +++ b/src/main/java/com/sluv/server/domain/auth/exception/UserBlockedException.java @@ -0,0 +1,13 @@ +package com.sluv.server.domain.auth.exception; + +import org.springframework.http.HttpStatus; + +public class UserBlockedException extends AuthException { + private static final int ERROR_CODE = 2023; + private static final String MESSAGE = "정지된 유저입니다."; + private static final HttpStatus STATUS = HttpStatus.BAD_REQUEST; + + public UserBlockedException() { + super(ERROR_CODE, STATUS, MESSAGE); + } +} diff --git a/src/main/java/com/sluv/server/domain/user/service/UserService.java b/src/main/java/com/sluv/server/domain/user/service/UserService.java index 12160c32..73a63899 100644 --- a/src/main/java/com/sluv/server/domain/user/service/UserService.java +++ b/src/main/java/com/sluv/server/domain/user/service/UserService.java @@ -1,5 +1,6 @@ package com.sluv.server.domain.user.service; +import com.sluv.server.domain.auth.exception.UserBlockedException; import com.sluv.server.domain.celeb.dto.*; import com.sluv.server.domain.celeb.entity.Celeb; import com.sluv.server.domain.celeb.entity.CelebCategory; @@ -604,4 +605,11 @@ private void changeCategoryOrder(List categoryList) { categoryList.set(1, categoryList.get(2)); categoryList.set(2, tempCategory); } + + public void checkUserStatue(User user) { + + if (user.getUserStatus().equals(UserStatus.BLOCKED)){ + throw new UserBlockedException(); + } + } }