From 19f40ba00610b8b1f9fd857493e37e3a97ecdb73 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 29 Oct 2023 20:01:24 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=20=EC=B9=B4=EC=B9=B4=EC=98=A4,=20?= =?UTF-8?q?=EA=B5=AC=EA=B8=80=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=99=80=20=EC=A0=80=EC=9E=A5,=20=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../user/controller/AuthController.java | 27 --------- .../dto/response/GoogleUserResponseDto.java | 6 +- .../dto/response/KakaoUserResponseDto.java | 56 ++++++++++--------- .../server/farmususer/user/entity/User.java | 8 +++ .../farmususer/user/service/AuthService.java | 36 ++++-------- 6 files changed, 50 insertions(+), 85 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 5213cb3..e1c3968 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_11/에러처리-추가"] + branches: ["feature_13/카카오,-구글-로그인-수정"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java index bcbae14..72beb69 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java @@ -36,33 +36,6 @@ public TokenResponseDto kakaoLogin(HttpServletRequest request) { return reissueTokenResponseDto; } -// -// @DeleteMapping("/logout") -// public ResponseDto logout(HttpServletRequest request) { -// -// -// String userId = jwtTokenProvider.getUserId(request); -// -// ResponseDto logoutResponseDto = authService.logout(Long.valueOf(userId)); -// -// LOGGER.info("로그아웃 완료"); -// -// return logoutResponseDto; -// } -// -// @GetMapping(value = "/reissue-token") -// public TokenResponseDto reissueToken(HttpServletRequest request) { -// -// String userId = jwtTokenProvider.getUserId(request); -// String refreshToken = jwtTokenProvider.resolveToken(request); -// -// TokenResponseDto reissueTokenResponseDto = authService.reissueToken(refreshToken, Long.valueOf(userId)); -// -// LOGGER.info("토큰 재발급 완료"); -// -// return reissueTokenResponseDto; -// } - @PostMapping(value = "/google-login") public TokenResponseDto googleLogin(HttpServletRequest request) { diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java index 410a17f..6ede66f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java @@ -11,10 +11,6 @@ public class GoogleUserResponseDto { private String id; private String email; - private boolean verified_email; - private String name; - private String given_name; - private String family_name; private String picture; - private String locale; + private String name; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/KakaoUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/KakaoUserResponseDto.java index b2d1756..cd44f2f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/KakaoUserResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/KakaoUserResponseDto.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -9,6 +10,7 @@ @Getter @Builder +@AllArgsConstructor public class KakaoUserResponseDto { private long id; @@ -16,33 +18,33 @@ public class KakaoUserResponseDto { public KakaoUserResponseDto(@JsonProperty("id") long id) { this.id = id; } -// private UserProfileDTO kakao_account; -// -// -// @Setter -// @Getter -// public class UserProfileDTO { -// private boolean profileNicknameNeedsAgreement; -// private boolean profileImageNeedsAgreement; -// private ProfileData profile; -// private boolean hasEmail; -// private boolean emailNeedsAgreement; -// private boolean isEmailValid; -// private boolean isEmailVerified; -// private String email; -// -// -// -// -// @Getter -// @Setter -// public class ProfileData { -// private String nickname; -// private String thumbnailImageUrl; -// private String profileImageUrl; -// private boolean isDefaultImage; -// } -// } + private UserProfileDTO kakao_account; + + + @Setter + @Getter + public class UserProfileDTO { + private boolean profileNicknameNeedsAgreement; + private boolean profileImageNeedsAgreement; + private ProfileData profile; + private boolean hasEmail; + private boolean emailNeedsAgreement; + private boolean isEmailValid; + private boolean isEmailVerified; + private String email; + + + + + @Getter + @Setter + public class ProfileData { + private String nickname; + private String thumbnail_image_Url; + private String profile_image_url; + private boolean isDefaultImage; + } + } diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java index 7bf3e13..5893b64 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java @@ -35,4 +35,12 @@ public class User { private String role; + @Size(max = 45) + @Column(name = "nickname", length = 45) + private String nickname; + + @Size(max = 255) + @Column(name = "profile_image") + private String profileImage; + } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 20add15..5f7075a 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -1,5 +1,6 @@ package modernfarmer.server.farmususer.user.service; + import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.KakaoUserResponseDto; @@ -9,7 +10,6 @@ import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @@ -44,23 +44,18 @@ public TokenResponseDto googleLogin(String accessToken) { Mono userInfoMono = getUserGoogleInfo(accessToken); GoogleUserResponseDto userInfo = userInfoMono.block(); -// LOGGER.info(String.valueOf(userInfo.getAccount_email())); -// LOGGER.info(String.valueOf(userInfo.getProfile_nickname())); -// LOGGER.info(String.valueOf(userInfo.getProfile_image())); - -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getEmail())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfileImageUrl())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); Optional userData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); + log.info(String.valueOf(userInfo.getEmail())); + log.info(String.valueOf(userInfo.getPicture())); + log.info(String.valueOf(userInfo.getId())); + if(userData.isEmpty()){ user = User.builder() .usernumber(String.valueOf(userInfo.getId())) .role("USER") -// .email(userInfo.getKakao_account().getEmail()) -// .nickname(userInfo.getKakao_account().getProfile().getNickname()) -// .userProfile(userInfo.getKakao_account().getProfile().getProfileImageUrl()) + .profileImage(userInfo.getPicture()) .build(); userRepository.save(user); @@ -80,8 +75,6 @@ public TokenResponseDto googleLogin(String accessToken) { .refreshToken(refreshToken) .build(); -// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"userId", String.valueOf(userLoginData.get().getId())); -// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"role", String.valueOf(userLoginData.get().getRole())); redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); @@ -95,13 +88,11 @@ public TokenResponseDto kakaoLogin(String accessToken) { Mono userInfoMono = getUserKakaoInfo(accessToken); KakaoUserResponseDto userInfo = userInfoMono.block(); -// LOGGER.info(String.valueOf(userInfo.getAccount_email())); -// LOGGER.info(String.valueOf(userInfo.getProfile_nickname())); -// LOGGER.info(String.valueOf(userInfo.getProfile_image())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getEmail())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfileImageUrl())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); + log.info(String.valueOf(userInfo.getKakao_account().getEmail())); + log.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfile_image_url())); + log.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); + Optional userData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); @@ -109,9 +100,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { user = User.builder() .usernumber(String.valueOf(userInfo.getId())) .role("USER") -// .email(userInfo.getKakao_account().getEmail()) -// .nickname(userInfo.getKakao_account().getProfile().getNickname()) -// .userProfile(userInfo.getKakao_account().getProfile().getProfileImageUrl()) + .profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url()) .build(); userRepository.save(user); @@ -131,8 +120,6 @@ public TokenResponseDto kakaoLogin(String accessToken) { .refreshToken(refreshToken) .build(); -// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"userId", String.valueOf(userLoginData.get().getId())); -// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"role", String.valueOf(userLoginData.get().getRole())); redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); @@ -140,7 +127,6 @@ public TokenResponseDto kakaoLogin(String accessToken) { return tokenResponseDto; } - public Mono getUserKakaoInfo(String accessToken) { return webClient .get() From fee7553ac583646925e53a8c4b9e973936e95e30 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 29 Oct 2023 20:14:26 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=9C=20=EC=B4=88=EA=B8=B0=20=EC=9C=A0=EC=A0=80,=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20=EC=9C=A0=EC=A0=80=20=EA=B5=AC=EB=B6=84=20?= =?UTF-8?q?boolean=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jpb/jpb-settings.xml | 10 ++++++++++ .../farmususer/user/dto/response/TokenResponseDto.java | 2 ++ .../server/farmususer/user/service/AuthService.java | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 .jpb/jpb-settings.xml diff --git a/.jpb/jpb-settings.xml b/.jpb/jpb-settings.xml new file mode 100644 index 0000000..484f362 --- /dev/null +++ b/.jpb/jpb-settings.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java index e746e38..d992472 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java @@ -17,4 +17,6 @@ public class TokenResponseDto { private String accessToken; private String refreshToken; + + private boolean early; } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 5f7075a..1b73a5c 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -28,6 +28,7 @@ public class AuthService{ public UserRepository userRepository; private final WebClient webClient; + private boolean early = false; @Autowired public AuthService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate redisTemplate) { @@ -57,6 +58,7 @@ public TokenResponseDto googleLogin(String accessToken) { .role("USER") .profileImage(userInfo.getPicture()) .build(); + early = true; userRepository.save(user); } @@ -69,6 +71,7 @@ public TokenResponseDto googleLogin(String accessToken) { TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") .code(200) + .early(early) .accessToken(jwtTokenProvider.createAccessToken( userLoginData.get().getId(), String.valueOf(userLoginData.get().getRole()))) @@ -103,6 +106,8 @@ public TokenResponseDto kakaoLogin(String accessToken) { .profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url()) .build(); + early = true; + userRepository.save(user); } @@ -114,6 +119,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") .code(200) + .early(early) .accessToken(jwtTokenProvider.createAccessToken( userLoginData.get().getId(), String.valueOf(userLoginData.get().getRole())))