Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 13/카카오, 구글 로그인 수정 #15

Merged
merged 2 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD

on:
push:
branches: ["feature_11/에러처리-추가"]
branches: ["feature_13/카카오,-구글-로그인-수정"]

pull_request:
branches: ["dev"]
Expand Down
10 changes: 10 additions & 0 deletions .jpb/jpb-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaPluginProjectSettings">
<option name="entityNameTemplate" />
<option name="isLombokBuilder" value="true" />
<option name="isLombokAllArgsConstructor" value="true" />
<option name="isLombokNoArgsConstructor" value="true" />
<option name="scaffoldingLanguage" />
</component>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,49 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;


@Getter
@Builder
@AllArgsConstructor
public class KakaoUserResponseDto {

private long id;
@JsonCreator
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;
}
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class TokenResponseDto {
private String accessToken;

private String refreshToken;

private boolean early;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<String, String> redisTemplate) {
Expand All @@ -44,24 +45,20 @@ public TokenResponseDto googleLogin(String accessToken) {
Mono<GoogleUserResponseDto> 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<User> 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();
early = true;

userRepository.save(user);
}
Expand All @@ -74,14 +71,13 @@ 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())))
.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);

Expand All @@ -95,25 +91,23 @@ public TokenResponseDto kakaoLogin(String accessToken) {
Mono<KakaoUserResponseDto> 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<User> userData = userRepository.findByUsernumber(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.getKakao_account().getProfile().getProfile_image_url())
.build();

early = true;

userRepository.save(user);
}

Expand All @@ -125,22 +119,20 @@ 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())))
.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);


return tokenResponseDto;
}


public Mono<KakaoUserResponseDto> getUserKakaoInfo(String accessToken) {
return webClient
.get()
Expand Down