From 6cececadd7dfcfb6643be35a2167560c7d04771c Mon Sep 17 00:00:00 2001 From: hyunho Date: Wed, 25 Nov 2020 07:04:00 +0000 Subject: [PATCH] --- FO/Controllers/AccountController.cs | 4 + FO/FO.csproj | 1 + FO/Views/Account/IndexBase.cshtml | 27 +++--- FO/Views/Account/Join.cshtml | 132 +++++++++++++++++--------- FO/Views/Account/JoinTSel.cshtml | 35 +++---- FO/Views/Account/KakaoCallback.cshtml | 72 ++++++++++++++ FO/Views/Account/NaverCallback.cshtml | 4 +- 7 files changed, 192 insertions(+), 83 deletions(-) create mode 100644 FO/Views/Account/KakaoCallback.cshtml diff --git a/FO/Controllers/AccountController.cs b/FO/Controllers/AccountController.cs index 211f140..cf6c05d 100644 --- a/FO/Controllers/AccountController.cs +++ b/FO/Controllers/AccountController.cs @@ -844,6 +844,10 @@ namespace NP.FO.Controllers { return View(); } + public ActionResult KakaoCallback() + { + return View(); + } public String XPayVBankMoney() { diff --git a/FO/FO.csproj b/FO/FO.csproj index 963bc9d..6c456b5 100644 --- a/FO/FO.csproj +++ b/FO/FO.csproj @@ -669,6 +669,7 @@ + diff --git a/FO/Views/Account/IndexBase.cshtml b/FO/Views/Account/IndexBase.cshtml index 2f03842..22dbe5e 100644 --- a/FO/Views/Account/IndexBase.cshtml +++ b/FO/Views/Account/IndexBase.cshtml @@ -1,4 +1,8 @@ @model NP.Model.VMUser +@{ + var naverClientId = "fvaj0CdI04awGMEhaICy"; + var kakaoAppkey = "7b09519e7bce67d548a2a594a48acf63"; +} @@ -101,21 +105,16 @@ } var naverLogin = new naver.LoginWithNaverId( { - clientId: "fvaj0CdI04awGMEhaICy", //개발자센터에 등록한 ClientID - callbackUrl: "https://www.ynicte.com/Account/NaverCallback",//개발자센터에 등록한 callback Url - isPopup: false, /* 팝업을 통한 연동처리 여부 */ - loginButton: { color: "green", type: 3, height: 60 }, /* 로그인 버튼의 타입을 지정 */ + clientId: "@naverClientId", + callbackUrl: "https://www.ynicte.com/Account/NaverCallback", + isPopup: false, + loginButton: { color: "green", type: 3, height: 60 }, } ); function loginWithKakao() { - Kakao.Auth.login({ - success: function (authObj) { - alert(JSON.stringify(authObj)) - }, - fail: function (err) { - alert(JSON.stringify(err)) - }, + Kakao.Auth.authorize({ + redirectUri: 'https://www.ynicte.com/Account/KakaoCallback' }) } @@ -124,11 +123,7 @@ } function snsInit() { - // 카카오 SDK를 초기화 합니다. 사용할 앱의 JavaScript 키를 설정해 주세요. - Kakao.init('f30a121bf140bf3d3dbf72012b7d713c'); - // SDK 초기화 여부를 판단합니다. - console.log(Kakao.isInitialized()); - /* 네이버 설정정보를 초기화하고 연동을 준비 */ naverLogin.init(); + Kakao.init("@kakaoAppkey"); } \ No newline at end of file diff --git a/FO/Views/Account/Join.cshtml b/FO/Views/Account/Join.cshtml index 4e0718d..575909e 100644 --- a/FO/Views/Account/Join.cshtml +++ b/FO/Views/Account/Join.cshtml @@ -4,6 +4,9 @@ var em = new NP.Model.MenuPage(); var mainprivate = (menus.Where(w => w.refcode == "main.private").FirstOrDefault() ?? em); var mainagree = (menus.Where(w => w.refcode == "main.agree").FirstOrDefault() ?? em); + + var naverClientId = "fvaj0CdI04awGMEhaICy"; + var kakaoAppkey = "7b09519e7bce67d548a2a594a48acf63"; } @@ -213,54 +216,93 @@ else } } - /*(1) 네이버 Javscript 설정 정보 및 초기화*/ - var naverLogin = new naver.LoginWithNaverId( - { - clientId: "fvaj0CdI04awGMEhaICy", //개발자센터에 등록한 ClientID - callbackUrl: "https://www.ynicte.com/Account/Join",//개발자센터에 등록한 callback Url - isPopup: false, /* 팝업을 통한 연동처리 여부 */ - callbackHandle: true - /* callback 페이지가 분리되었을 경우에 callback 페이지에서는 callback처리를 해줄수 있도록 설정합니다. */ - } - ); - /* (2) 네이버 로그인 정보를 초기화하기 위하여 init을 호출 */ - naverLogin.init(); - - /* (3) Callback의 처리. 정상적으로 Callback 처리가 완료될 경우 main page로 redirect(또는 Popup close) */ window.addEventListener('load', function () { - naverLogin.getLoginStatus(function (status) { - if (status) { - /* (4) 필수적으로 받아야하는 프로필 정보가 있다면 callback처리 시점에 체크 */ - var email = naverLogin.user.getEmail(); - var name = naverLogin.user.getName(); - var uniqId = naverLogin.user.getId(); - var profileImage = naverLogin.user.getProfileImage(); - var birthday = naverLogin.user.getBirthday(); - var age = naverLogin.user.getAge(); - if (email == undefined || email == null) { - alert("이메일은 필수정보입니다. 정보제공을 동의해주세요."); - /* (4-1) 사용자 정보 재동의를 위하여 다시 네이버로그인 동의페이지로 이동함 */ - naverLogin.reprompt(); - return; - } - if (name == undefined || name == null) { - alert("이름은 필수정보입니다. 정보제공을 동의해주세요."); - naverLogin.reprompt(); - return; + if (@Request["jointype"] == "2") { + var naverLogin = new naver.LoginWithNaverId( + { + clientId: "@naverClientId", + callbackUrl: "https://www.ynicte.com/Account/Join?jointype=2", + isPopup: false, + callbackHandle: true } + ); - $("#username").val(name); - $("#email").val(email); - $("#snsid").val(uniqId); - $("#jointype").val(2); //0:일반회원가입,1:google,2:naver,3:kakao - $("#username").prop("readonly", "readonly"); - $("#username").css("background-color", "#ddd"); - $("#email").prop("readonly", "readonly"); - $("#email").css("background-color", "#ddd"); - } else { - console.log("callback 처리에 실패하였습니다."); - } - }); + naverLogin.init(); + naverLogin.getLoginStatus(function (status) { + if (status) { + var email = naverLogin.user.getEmail(); + var name = naverLogin.user.getName(); + var uniqId = naverLogin.user.getId(); + var profileImage = naverLogin.user.getProfileImage(); + var birthday = naverLogin.user.getBirthday(); + var age = naverLogin.user.getAge(); + if (email == undefined || email == null) { + alert("이메일은 필수정보입니다. 정보제공을 동의해주세요."); + naverLogin.reprompt(); + return; + } + if (name == undefined || name == null) { + alert("이름은 필수정보입니다. 정보제공을 동의해주세요."); + naverLogin.reprompt(); + return; + } + + $("#username").val(name); + $("#email").val(email); + $("#snsid").val(uniqId); + $("#jointype").val(2); //0:일반회원가입,1:google,2:naver,3:kakao + $("#username").prop("readonly", "readonly"); + $("#username").css("background-color", "#ddd"); + $("#email").prop("readonly", "readonly"); + $("#email").css("background-color", "#ddd"); + } else { + console.log("callback 처리에 실패하였습니다."); + } + }); + } + if (@Request["jointype"] == "3") { + $.when( + Kakao.init("@kakaoAppkey"), + kakaoDisplayToken() + ).done(function () { + Kakao.API.request({ + url: '/v2/user/me', + success: function (res) { + $("#username").val(res.properties.nickname); + $("#email").val(res.kakao_account.email); + $("#snsid").val(res.id); + $("#jointype").val(3); //0:일반회원가입,1:google,2:naver,3:kakao + $("#username").prop("readonly", "readonly"); + $("#username").css("background-color", "#ddd"); + $("#email").prop("readonly", "readonly"); + $("#email").css("background-color", "#ddd"); + }, + fail: function (error) { + console.log(error); + } + }); + }); + + } }); + + function kakaoDisplayToken() { + const token = getKakaoCookie('authorize-access-token') + if (token) { + Kakao.Auth.setAccessToken(token) + Kakao.Auth.getStatusInfo(({ status }) => { + if (status === 'connected') { + document.getElementById('token-result').innerText = 'login success. token: ' + Kakao.Auth.getAccessToken() + } else { + Kakao.Auth.setAccessToken(null) + } + }) + } + } + function getKakaoCookie(name) { + const value = "; " + document.cookie; + const parts = value.split("; " + name + "="); + if (parts.length === 2) return parts.pop().split(";").shift(); + } } \ No newline at end of file diff --git a/FO/Views/Account/JoinTSel.cshtml b/FO/Views/Account/JoinTSel.cshtml index c063e27..2a49e53 100644 --- a/FO/Views/Account/JoinTSel.cshtml +++ b/FO/Views/Account/JoinTSel.cshtml @@ -1,4 +1,8 @@ - +@{ + var naverClientId = "fvaj0CdI04awGMEhaICy"; + var kakaoAppkey = "7b09519e7bce67d548a2a594a48acf63"; +} + @@ -15,6 +19,8 @@
  • 구글 아이디로 회원가입
  • + + @@ -25,36 +31,25 @@ }); var naverLogin = new naver.LoginWithNaverId( { - clientId: "fvaj0CdI04awGMEhaICy", //개발자센터에 등록한 ClientID - callbackUrl: "https://www.ynicte.com/Account/Join",//개발자센터에 등록한 callback Url //회원가입 페이지로 이동시킨다 - isPopup: false, /* 팝업을 통한 연동처리 여부 */ - loginButton: { color: "green", type: 3, height: 60 } /* 로그인 버튼의 타입을 지정 */ + clientId: "@naverClientId", + callbackUrl: "https://www.ynicte.com/Account/Join?jointype=2", + isPopup: false, + loginButton: { color: "green", type: 3, height: 60 } } ); function loginWithKakao() { - Kakao.Auth.login({ - success: function (authObj) { - alert(JSON.stringify(authObj)) - }, - fail: function (err) { - alert(JSON.stringify(err)) - }, + Kakao.Auth.authorize({ + redirectUri: 'https://www.ynicte.com/Account/Join?jointype=3' }) } function loginWithNaver() { - $("#naverIdLogin_loginButton > img").trigger("click"); + $("#naverIdLogin_loginButton > img").trigger("click"); } function snsInit() { - /* 네이버 설정정보를 초기화하고 연동을 준비 */ naverLogin.init(); - // 카카오 SDK를 초기화 합니다. 사용할 앱의 JavaScript 키를 설정해 주세요. - Kakao.init('f30a121bf140bf3d3dbf72012b7d713c'); - // SDK 초기화 여부를 판단합니다. - console.log(Kakao.isInitialized()); - + Kakao.init("@kakaoAppkey"); } - \ No newline at end of file diff --git a/FO/Views/Account/KakaoCallback.cshtml b/FO/Views/Account/KakaoCallback.cshtml new file mode 100644 index 0000000..8aa001a --- /dev/null +++ b/FO/Views/Account/KakaoCallback.cshtml @@ -0,0 +1,72 @@ +@{ + Layout = null; + var kakaoAppkey = "7b09519e7bce67d548a2a594a48acf63"; +} + + @Html.Partial("./Partial/JS") + + + \ No newline at end of file diff --git a/FO/Views/Account/NaverCallback.cshtml b/FO/Views/Account/NaverCallback.cshtml index bbf4b11..5d2e0a5 100644 --- a/FO/Views/Account/NaverCallback.cshtml +++ b/FO/Views/Account/NaverCallback.cshtml @@ -1,18 +1,18 @@ @{ Layout = null; + var naverClientId = "fvaj0CdI04awGMEhaICy"; } @Html.Partial("./Partial/JS") -