From 7d2da3c8a31de55061934601561651f109a45b6e Mon Sep 17 00:00:00 2001 From: JSYOO Date: Thu, 23 Dec 2021 11:29:25 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B9=B4=EC=B9=B4=EC=98=A4=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=B6=80=EB=B6=84=20=EC=97=90=EB=9F=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ext/oauth/service/OAuthLogin.java | 28 +++++++++++++++---- .../java/nlib/user/web/LoginController.java | 25 +++++++++++++---- .../jsp/nlib/member/insertMemberInfoForm.jsp | 16 ++++++++--- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/main/java/egovframework/com/ext/oauth/service/OAuthLogin.java b/src/main/java/egovframework/com/ext/oauth/service/OAuthLogin.java index a90ddb8f..26df92ed 100644 --- a/src/main/java/egovframework/com/ext/oauth/service/OAuthLogin.java +++ b/src/main/java/egovframework/com/ext/oauth/service/OAuthLogin.java @@ -1,5 +1,8 @@ package egovframework.com.ext.oauth.service; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.ScopeBuilder; @@ -10,6 +13,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import nlib.user.web.LoginController; import nlib.util.StringUtil; @@ -18,6 +22,7 @@ public class OAuthLogin { /** SNS 호출 시, URL callType 대체 문자열 */ public static final String CALL_TYPE_LOGIN = "login"; public static final String CALL_TYPE_MEMBER = "member"; + private static final Logger log = LoggerFactory.getLogger(OAuthLogin.class); private OAuth20Service oauthService; private OAuthVO oauthVO; @@ -61,9 +66,9 @@ public class OAuthLogin { } public OAuthUniversalUser getUserProfile(String code) throws Exception { - + log.debug("getUserProfile > getAccessToken"); OAuth2AccessToken accessToken = oauthService.getAccessToken(code); - + log.debug("getUserProfile > getAccessToken2"); OAuthRequest request = new OAuthRequest(Verb.GET, this.oauthVO.getProfileUrl()); oauthService.signRequest(accessToken, request); @@ -153,7 +158,9 @@ public class OAuthLogin { user.setSnsType(OAuthConfig.KAKAO_SERVICE_NAME); JsonNode resNode = rootNode.get("kakao_account"); - user.setSnsId((rootNode.get("id").asText() == null) ? "" : rootNode.get("id").asText()); + if(rootNode.has("id")) { + user.setSnsId((rootNode.get("id").asText() == null) ? "" : rootNode.get("id").asText()); + } if (resNode.has("email")) { user.setSnsUserId(StringUtil.getString(resNode.get("email").asText(), "")); @@ -170,8 +177,19 @@ public class OAuthLogin { user.setSnsGender("F"); } } - if (resNode.has("birthday") || resNode.has("birthyear")) - user.setSnsUserId((resNode.get("email").asText() == null) ? "" : resNode.get("email").asText()); + // 생년월일 + String birthday ="0000"; + String birthyear = "0000"; + if (resNode.has("birthday")) { + birthday = StringUtil.getString(resNode.get("birthday").asText(), "0000"); + } + if (resNode.has("birthyear")) { + birthyear = StringUtil.getString(resNode.get("birthyear").asText(), "0000"); + } + birthday = birthday.replaceAll("-", ""); + if(birthday.length() != 4) birthday = "0000"; + if(birthyear.length() != 4) birthyear = "0000"; + user.setSnsBirthday(birthyear + birthday); if (resNode.has("phone_number")) user.setSnsMobileNo(StringUtil.getString(resNode.get("phone_number").asText(), "")); diff --git a/src/main/java/nlib/user/web/LoginController.java b/src/main/java/nlib/user/web/LoginController.java index 492a272d..eb6e47e3 100644 --- a/src/main/java/nlib/user/web/LoginController.java +++ b/src/main/java/nlib/user/web/LoginController.java @@ -406,13 +406,20 @@ public class LoginController extends NlibCommonController { // SNS 클라이언트 설정 정보 할당 OAuthVO oauthVO = null; - if (StringUtil.equalsIgnoreCase(OAuthConfig.NAVER_SERVICE_NAME, oauthServiceName)) + if (StringUtil.equalsIgnoreCase(OAuthConfig.NAVER_SERVICE_NAME, oauthServiceName)) { + log.debug("callbackOauth > NAVER_SERVICE_NAME"); oauthVO = naverAuthVO; - else if (StringUtil.equalsIgnoreCase(OAuthConfig.GOOGLE_SERVICE_NAME, oauthServiceName)) + } + else if (StringUtil.equalsIgnoreCase(OAuthConfig.GOOGLE_SERVICE_NAME, oauthServiceName)) { + log.debug("callbackOauth > GOOGLE_SERVICE_NAME"); oauthVO = googleAuthVO; - else if (StringUtil.equalsIgnoreCase(OAuthConfig.KAKAO_SERVICE_NAME, oauthServiceName)) + } + else if (StringUtil.equalsIgnoreCase(OAuthConfig.KAKAO_SERVICE_NAME, oauthServiceName)) { + log.debug("callbackOauth > KAKAO_SERVICE_NAME"); oauthVO = kakaoAuthVO; + } else { + log.debug("callbackOauth > SNS 연동 콜백정보가 올바르지 않습니다."); throw new Exception("SNS 연동 콜백정보가 올바르지 않습니다."); } @@ -420,9 +427,15 @@ public class LoginController extends NlibCommonController { // 1. code를 이용해서 Access Token 받기 // 2. Access Token을 이용해서 사용자 제공 정보 가져오기 //----------------------------------------------- + OAuthLogin oauthLogin = new OAuthLogin(oauthVO, callType); - OAuthUniversalUser oauthUser = oauthLogin.getUserProfile(code); // 1,2번 동시 - log.debug("oauthLoginCallback > Profile ===>>" + oauthUser.getSnsId() + ", " + oauthUser.getSnsName()); + OAuthUniversalUser oauthUser = null; + try { + oauthUser = oauthLogin.getUserProfile(code); // 1,2번 동시 + } catch(Exception e) { + log.debug("oauthLoginCallback > SNS 연동 콜백정보 코드가 업습니다. error ===>>" + e.toString()); + throw new Exception("SNS 연동 콜백정보 코드가 업습니다."); + } // oAuth를 통한 SNS연동이 실패한 경우 if(oauthUser == null || !oauthUser.isValid()) { @@ -432,6 +445,8 @@ public class LoginController extends NlibCommonController { return "nlib/login/loginPreSet"; } + log.debug("oauthLoginCallback > Profile ===>>" + oauthUser.getSnsId() + ", " + oauthUser.getSnsName()); + //----------------------------------------------- // 해당 처리기로 전환 //----------------------------------------------- diff --git a/src/main/webapp/WEB-INF/jsp/nlib/member/insertMemberInfoForm.jsp b/src/main/webapp/WEB-INF/jsp/nlib/member/insertMemberInfoForm.jsp index 8747c471..8995ce88 100644 --- a/src/main/webapp/WEB-INF/jsp/nlib/member/insertMemberInfoForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/nlib/member/insertMemberInfoForm.jsp @@ -181,10 +181,18 @@ $(document).ready(function() { { birth_dd = birth_dd.substr(1,1) } - - $("#birth_yy").val(birth_yy).prop("selected", true); - $("#birth_mm").val(birth_mm).prop("selected", true); - $("#birth_dd").val(birth_dd).prop("selected", true); + if(birth_yy != "0000") + { + $("#birth_yy").val(birth_yy).prop("selected", true); + } + if(birth_mm != "00") + { + $("#birth_mm").val(birth_mm).prop("selected", true); + } + if(birth_dd != "00") + { + $("#birth_dd").val(birth_dd).prop("selected", true); + } } var mobileNo="";