This commit is contained in:
hyunho 2020-11-27 00:31:40 +00:00
parent 7a0547d7ff
commit 44f482dd80
8 changed files with 330 additions and 176 deletions

View File

@ -18,6 +18,11 @@ namespace NP.FO.Controllers
{ {
public class AccountController : FOOpenBaseController public class AccountController : FOOpenBaseController
{ {
//전역변수 SNS 로그인 ClientID
private string naverClientID = "fvaj0CdI04awGMEhaICy";
private string kakaoClientID = "7b09519e7bce67d548a2a594a48acf63";
private string googleClientID = "710934829793-eojibithnhn6t0ltq2dd1g1kunpiqbao.apps.googleusercontent.com";
public ActionResult FindMe(VMUser vm) public ActionResult FindMe(VMUser vm)
{ {
vm.User = new Users() { }; vm.User = new Users() { };
@ -34,6 +39,10 @@ namespace NP.FO.Controllers
return View(vm); return View(vm);
} }
public ActionResult Index(VMUser vm){ public ActionResult Index(VMUser vm){
ViewBag.naverClientID = naverClientID;
ViewBag.kakaoClientID = kakaoClientID;
ViewBag.googleClientID = googleClientID;
if (Request.IsAjaxRequest()){ if (Request.IsAjaxRequest()){
return JsonError<String>(Base.ENUM.JSONCode.Error, "403:" + Request.Url.AbsolutePath, "0112"); return JsonError<String>(Base.ENUM.JSONCode.Error, "403:" + Request.Url.AbsolutePath, "0112");
} }
@ -81,6 +90,9 @@ namespace NP.FO.Controllers
{ {
ViewBag.JoinOK = true; ViewBag.JoinOK = true;
} }
ViewBag.naverClientID = naverClientID;
ViewBag.kakaoClientID = kakaoClientID;
ViewBag.googleClientID = googleClientID;
return View(vm); return View(vm);
//} //}
} }
@ -447,6 +459,9 @@ namespace NP.FO.Controllers
public ActionResult JoinTSel() public ActionResult JoinTSel()
{ {
ViewBag.naverClientID = naverClientID;
ViewBag.kakaoClientID = kakaoClientID;
ViewBag.googleClientID = googleClientID;
return View(); return View();
} }
@ -842,14 +857,30 @@ namespace NP.FO.Controllers
public ActionResult NaverCallback() public ActionResult NaverCallback()
{ {
ViewBag.naverClientID = naverClientID;
ViewBag.kakaoClientID = kakaoClientID;
ViewBag.googleClientID = googleClientID;
return View(); return View();
} }
public ActionResult NaverCallbackJoin() public ActionResult NaverCallbackJoin()
{ {
ViewBag.naverClientID = naverClientID;
ViewBag.kakaoClientID = kakaoClientID;
ViewBag.googleClientID = googleClientID;
return View(); return View();
} }
public ActionResult KakaoCallback() public ActionResult KakaoCallback()
{ {
ViewBag.naverClientID = naverClientID;
ViewBag.kakaoClientID = kakaoClientID;
ViewBag.googleClientID = googleClientID;
return View();
}
public ActionResult GoogleCallback()
{
ViewBag.naverClientID = naverClientID;
ViewBag.kakaoClientID = kakaoClientID;
ViewBag.googleClientID = googleClientID;
return View(); return View();
} }

View File

@ -671,6 +671,7 @@
<Content Include="Views\Account\NaverCallback.cshtml" /> <Content Include="Views\Account\NaverCallback.cshtml" />
<Content Include="Views\Account\KakaoCallback.cshtml" /> <Content Include="Views\Account\KakaoCallback.cshtml" />
<Content Include="Views\Account\NaverCallbackJoin.cshtml" /> <Content Include="Views\Account\NaverCallbackJoin.cshtml" />
<Content Include="Views\Account\GoogleCallback.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />

View File

@ -0,0 +1,44 @@
@{
Layout = null;
var naverClientId = ViewBag.naverClientID;
var kakaoClientId = ViewBag.kakaoClientID;
var googleClientId = ViewBag.googleClientID;
}
<head>
@Html.Partial("./Partial/JS")
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="@googleClientId">
</head>
<div class="g-signin2" data-onsuccess="onGoogleLogIn" style="display:none"></div> @*구글로그인관련*@
<script>
var snsid;
function onGoogleLogIn(googleUser) {
var profile = googleUser.getBasicProfile();
snsid = profile.getId();
capp("/focommon/CheckExistSnsId", { snsid: snsid, jointype: 1 }, "snslogin");
}
function snslogin() {
if (capResult.code > 0) {
capp("/focommon/SnsLogin", { uid: snsid, isSns: true }, "goHome()");
}
else {
if (confirm("SNS 회원정보가 존재하지 않습니다.\r\n회원가입 페이지로 이동하시겠습니까?")) {
goJoin();
}
else {
goIndex();
}
}
}
function goJoin() {
location.href = "https://www.ynicte.com/Account/JoinTSel";
}
function goHome() {
location.href = "https://www.ynicte.com";
}
function goIndex() {
location.href = "https://www.ynicte.com/Account/Index";
}
</script>

View File

@ -1,11 +1,13 @@
@model NP.Model.VMUser @model NP.Model.VMUser
@{ @{
var naverClientId = "fvaj0CdI04awGMEhaICy"; var naverClientId = ViewBag.naverClientID;
var kakaoAppkey = "7b09519e7bce67d548a2a594a48acf63"; var kakaoClientId = ViewBag.kakaoClientID;
var googleClientId = ViewBag.googleClientID;
} }
<head> <head>
<script type="text/javascript" src="/js/naveridlogin_js_sdk_2.0.0.js"></script> <script type="text/javascript" src="/js/naveridlogin_js_sdk_2.0.0.js"></script>
<script type="text/javascript" src="/js/kakao.js"></script> <script type="text/javascript" src="/js/kakao.js"></script>
<script src="https://apis.google.com/js/platform.js?onload=googleInit" async defer></script>
</head> </head>
<form id="mform" action="" method="post"> <form id="mform" action="" method="post">
<div class="lgnWrap"> <div class="lgnWrap">
@ -34,12 +36,15 @@
<li> <li>
<a href="javascript:loginWithKakao()">카카오 아이디로 로그인</a> <a href="javascript:loginWithKakao()">카카오 아이디로 로그인</a>
</li> </li>
<li><a href="#">구글 아이디로 로그인</a></li> <li>
<a href="javascript:loginWithGoogle()">구글 아이디로 로그인</a>
</li>
</ul> </ul>
</div> </div>
</form> </form>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
if (opener != null && opener._ismain == 1) { if (opener != null && opener._ismain == 1) {
opener.location.href = "/Account/Index"; opener.location.href = "/Account/Index";
@ -76,9 +81,23 @@
} }
}); });
} }
snsInit(); snsInit();
}); });
var gauth;
function googleInit() {
gapi.load('auth2', function () {
var gauth = gapi.auth2.init({
client_id: "@googleClientId",
scope: 'profile'
});
gauth.then(function () {
console.log('google init success');
}, function () {
console.error('google init fail');
})
});
}
function login() { function login() {
if (val("uid") != "" && val("upw") != "") { if (val("uid") != "" && val("upw") != "") {
capp("/focommon/login", { uid: val("uid"), upw: val("upw"), issaveid: $("#issaveid").prop("checked") }, "cblogin"); capp("/focommon/login", { uid: val("uid"), upw: val("upw"), issaveid: $("#issaveid").prop("checked") }, "cblogin");
@ -113,23 +132,33 @@
); );
function loginWithKakao() { function loginWithKakao() {
Kakao.Auth.login({ Kakao.Auth.login({
success: function (authObj) { success: function (authObj) {
location.href = "https://www.ynicte.com/Account/KakaoCallback" location.href = "https://www.ynicte.com/Account/KakaoCallback"
}, },
fail: function (err) { fail: function (err) {
alert("카카오 아이디로 로그인에 실패했습니다."); alert("카카오 아이디로 로그인에 실패했습니다.");
console.log(JSON.stringify(err)) console.log(JSON.stringify(err))
}, },
}) })
} }
function loginWithGoogle() {
gauth = gapi.auth2.getAuthInstance();
gauth.signIn().then(function () {
location.href = "https://www.ynicte.com/Account/GoogleCallback"
}, function () {
alert("구글 아이디로 로그인에 실패했습니다.");
return;
});
}
function loginWithNaver() { function loginWithNaver() {
$("#naverIdLogin_loginButton > img").trigger("click"); $("#naverIdLogin_loginButton > img").trigger("click");
} }
function snsInit() { function snsInit() {
naverLogin.init(); naverLogin.init();
Kakao.init("@kakaoAppkey"); Kakao.init("@kakaoClientId");
} }
</script> </script>

View File

@ -5,13 +5,17 @@
var mainprivate = (menus.Where(w => w.refcode == "main.private").FirstOrDefault() ?? em); var mainprivate = (menus.Where(w => w.refcode == "main.private").FirstOrDefault() ?? em);
var mainagree = (menus.Where(w => w.refcode == "main.agree").FirstOrDefault() ?? em); var mainagree = (menus.Where(w => w.refcode == "main.agree").FirstOrDefault() ?? em);
var naverClientId = "fvaj0CdI04awGMEhaICy"; var naverClientId = ViewBag.naverClientID;
var kakaoAppkey = "7b09519e7bce67d548a2a594a48acf63"; var kakaoClientId = ViewBag.kakaoClientID;
var googleClientId = ViewBag.googleClientID;
} }
<head> <head>
<script type="text/javascript" src="/js/naveridlogin_js_sdk_2.0.0.js"></script> <script type="text/javascript" src="/js/naveridlogin_js_sdk_2.0.0.js"></script>
<script type="text/javascript" src="/js/kakao.js"></script> <script type="text/javascript" src="/js/kakao.js"></script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="@googleClientId">
</head> </head>
<div class="g-signin2" data-onsuccess="onGoogleLogIn" style="display:none"></div> @*구글로그인관련*@
@if (ViewBag.JoinOK) @if (ViewBag.JoinOK)
{ {
<ul class="jnStep"> <ul class="jnStep">
@ -72,7 +76,7 @@ else
<ul class="jnNum"> <ul class="jnNum">
<li><input type="text" id="userpno1" maxlength="6" class="int nocomma" value="@(!string.IsNullOrEmpty(Model.User.birthday) && Model.User.birthday.Length > 3 ? (Model.User.birthday ?? "").Substring(2) : "")" @(!string.IsNullOrEmpty(Model.User.birthday) ? Html.Raw("readonly=\"\" style=\"background-color:#ddd;\"") : Html.Raw(""))></li> <li><input type="text" id="userpno1" maxlength="6" class="int nocomma" value="@(!string.IsNullOrEmpty(Model.User.birthday) && Model.User.birthday.Length > 3 ? (Model.User.birthday ?? "").Substring(2) : "")" @(!string.IsNullOrEmpty(Model.User.birthday) ? Html.Raw("readonly=\"\" style=\"background-color:#ddd;\"") : Html.Raw(""))></li>
<li>-</li> <li>-</li>
<li><input type="tel" id="userpno2" maxlength="7" class="int nocomma" placeholder="주민등록번호 뒤 7자리"></li> <li><input type="tel" id="userpno2" maxlength="7" class="int nocomma" placeholder="주민등록번호 뒤 7자리"></li>
</ul> </ul>
</li> </li>
@*인증완료상태여도 재인증 가능*@ @*인증완료상태여도 재인증 가능*@
@ -126,163 +130,176 @@ else
@section scriptsHeader{ @section scriptsHeader{
@Html.Partial("./Partial/ScriptPost") @Html.Partial("./Partial/ScriptPost")
} }
@section scripts{ <script>
<script> function bindassign(v) {
function bindassign(v) { $("#asno").val(v.split(':')[0]);
$("#asno").val(v.split(':')[0]); $("#asname").val(v.split(':')[1]);
$("#asname").val(v.split(':')[1]); }
$(document).ready(function () {
if ('@(ViewBag.JoinOK?1:0)' == '1') {
$("#pageTitle h3").text("회원가입 완료");
} }
$(document).ready(function () { snsLogin();
if ('@(ViewBag.JoinOK?1:0)' == '1') { });
$("#pageTitle h3").text("회원가입 완료"); function save() {
} setv("userid", val("userid").replace(/ /, '').replace(/ /, ''));
}); setv("userpno", val("userpno1").replace(/ /, '').replace(/ /, '') + "" + val("userpno2").replace(/ /, '').replace(/ /, ''));
function save() { setv("userpass", val("userpass").replace(/ /, '').replace(/ /, ''));
setv("userid", val("userid").replace(/ /, '').replace(/ /, '')); setv("username", val("username").replace(/ /, '').replace(/ /, ''));
setv("userpno", val("userpno1").replace(/ /, '').replace(/ /, '') + "" + val("userpno2").replace(/ /, '').replace(/ /, '')); setv("email", val("email").replace(/ /, '').replace(/ /, ''));
setv("userpass", val("userpass").replace(/ /, '').replace(/ /, '')); setv("mobile", val("mobile").replace(/ /, '').replace(/ /, ''));
setv("username", val("username").replace(/ /, '').replace(/ /, '')); setv("mobile", formatmobile(val("mobile")));
setv("email", val("email").replace(/ /, '').replace(/ /, '')); //var userid = val("userid").replace(/[^(0-9a-zA-Z)]/gi, '');
setv("mobile", val("mobile").replace(/ /, '').replace(/ /, '')); if (check("username", null, "이름을 입력해주세요.")) { }
setv("mobile", formatmobile(val("mobile"))); else if (check("email", null, "이메일주소를 입력해주세요.")) { }
//var userid = val("userid").replace(/[^(0-9a-zA-Z)]/gi, ''); else if (!isemail(val("email"))) { focus("email"); msg("올바른 이메일주소를 입력해주세요."); }
if (check("username", null, "이름을 입력해주세요.")) { } else if (check("userid", null, "아이디를 입력해주세요.")) { }
else if (check("email", null, "이메일주소를 입력해주세요.")) { } else if (getBytes(val("userid")) < 5) { focus("userid"); msg("(5자이상, 영문/숫자/-/_) 규칙으로 아이디를 입력해주세요."); }
else if (!isemail(val("email"))) { focus("email"); msg("올바른 이메일주소를 입력해주세요."); } else if (!isid(val("userid"))) { focus("userid"); msg("(5자이상, 영문/숫자/-/_) 규칙으로 아이디를 입력해주세요."); }
else if (check("userid", null, "아이디를 입력해주세요.")) { } else if (val("IsSaveOK") != 1) { focus("userid"); msg("중복여부체크를 진행해주세요"); }
else if (getBytes(val("userid")) < 5) { focus("userid"); msg("(5자이상, 영문/숫자/-/_) 규칙으로 아이디를 입력해주세요."); } else if (check("userpass", null, "비밀번호를 입력해주세요.")) { }
else if (!isid(val("userid"))) { focus("userid"); msg("(5자이상, 영문/숫자/-/_) 규칙으로 아이디를 입력해주세요."); } else if (!ispassword(val("userpass"))) { focus("userpass"); msg("(8자 이상, 영문/숫자/특수기호 포함) 규칙으로 비밀번호를 입력해주세요."); }
else if (val("IsSaveOK") != 1) { focus("userid"); msg("중복여부체크를 진행해주세요"); } else if (val("userpass") != val("userpass2")) { focus("userpass2"); msg("비밀번호 확인이 다릅니다."); }
else if (check("userpass", null, "비밀번호를 입력해주세요.")) { } else if (check("userpno", null, "주민등록번호를 입력해주세요")) { }
else if (!ispassword(val("userpass"))) { focus("userpass"); msg("(8자 이상, 영문/숫자/특수기호 포함) 규칙으로 비밀번호를 입력해주세요."); } else if (getBytes(val("userpno1")) != 6 || getBytes(val("userpno2")) != 7) { focus("userpno2"); msg("주민등록번호를 확인해주세요"); }
else if (val("userpass") != val("userpass2")) { focus("userpass2"); msg("비밀번호 확인이 다릅니다."); } else if (!ismobilenumber(val("mobile"))) {focus("mobile");msg("핸드폰번호를 확인해주세요.");}
else if (check("userpno", null, "주민등록번호를 입력해주세요")) { } else if (check("post", null, "우편번호를 등록해주세요.") || check("address1", null, "우편번호를 등록해주세요.") || check("address2", null, "우편번호를 등록해주세요.")) { }
else if (getBytes(val("userpno1")) != 6 || getBytes(val("userpno2")) != 7) { focus("userpno2"); msg("주민등록번호를 확인해주세요"); } else if (check("asno", null, "직장을 등록해주세요.")) { }
else if (!ismobilenumber(val("mobile"))) {focus("mobile");msg("핸드폰번호를 확인해주세요.");} else if ($("input:radio[name='isassignuser']:checked").val() == null) { msg("채용형태를 선택해주세요"); }
else if (check("post", null, "우편번호를 등록해주세요.") || check("address1", null, "우편번호를 등록해주세요.") || check("address2", null, "우편번호를 등록해주세요.")) { } else if (check("uduty", null, "직위를 입력해주세요.")) { }
else if (check("asno", null, "직장을 등록해주세요.")) { } else if ($("input:radio[name='slevel']:checked").val() == null) { msg("학력을 선택해주세요"); }
else if ($("input:radio[name='isassignuser']:checked").val() == null) { msg("채용형태를 선택해주세요"); } else if (!$("#agree").prop("checked")) { $("#agree").focus(); msg("이용약관/개인정보처리방침에 동의해주세요."); }
else if (check("uduty", null, "직위를 입력해주세요.")) { } else {
else if ($("input:radio[name='slevel']:checked").val() == null) { msg("학력을 선택해주세요"); } cap("/focommon/join", "mform", "cbsave");
else if (!$("#agree").prop("checked")) { $("#agree").focus(); msg("이용약관/개인정보처리방침에 동의해주세요."); }
else {
cap("/focommon/join", "mform", "cbsave");
}
} }
function idcheck() { }
if (check("userid", null, "아이디를 입력해주세요.")) { } function idcheck() {
else if (getBytes(val("userid")) < 5) { focus("userid"); msg("(5자이상, 영문/숫자/-/_) 규칙으로 아이디를 입력해주세요."); } if (check("userid", null, "아이디를 입력해주세요.")) { }
else if (!isid(val("userid"))) { focus("userid"); msg("(5자이상, 영문/숫자/-/_) 규칙으로 아이디를 입력해주세요."); } else if (getBytes(val("userid")) < 5) { focus("userid"); msg("(5자이상, 영문/숫자/-/_) 규칙으로 아이디를 입력해주세요."); }
else { else if (!isid(val("userid"))) { focus("userid"); msg("(5자이상, 영문/숫자/-/_) 규칙으로 아이디를 입력해주세요."); }
capp("/focommon/idchk", { id: val("userid") }, "cbidchk"); else {
} capp("/focommon/idchk", { id: val("userid") }, "cbidchk");
} }
}
function cbidchk() { function cbidchk() {
if (capResult.code == 1000) { if (capResult.code == 1000) {
setv("IsSaveOK", 1); setv("IsSaveOK", 1);
msg("사용가능한 아이디입니다."); msg("사용가능한 아이디입니다.");
} else { } else {
focus("userid"); focus("userid");
msg("이미 사용중인 아이디입니다.<br />다른 아이디를 사용해주세요."); msg("이미 사용중인 아이디입니다.<br />다른 아이디를 사용해주세요.");
}
} }
}
function cbsave() { function cbsave() {
if (capResult.code == 1000) { if (capResult.code == 1000) {
setv("intval", 1); setv("intval", 1);
$("#mform").submit(); $("#mform").submit();
}
else if (capResult.obj == -1) {
focus("userid");
msg("이미 사용중인 아이디입니다.<br />다른 아이디를 사용해주세요.");
}
else if (capResult.obj == -2) {
focus("email");
msg("이미 사용중인 이메일입니다.<br />다른 이메일을 사용해주세요.");
}
else if (capResult.obj == -3) {
focus("mobile");
msg("이미 사용중인 핸드폰번호입니다.<br />다른 번호를 사용해주세요.");
}
} }
else if (capResult.obj == -1) {
function mobchk() { focus("userid");
//한번 인증되면 재인증 불가 msg("이미 사용중인 아이디입니다.<br />다른 아이디를 사용해주세요.");
if ($("#intval2").val() == 1 && $("#mobile").val() != null) {
msg("휴대폰 인증이 완료되었습니다.");
} else {
mobilechkview('MCHK');
}
} }
else if (capResult.obj == -2) {
focus("email");
msg("이미 사용중인 이메일입니다.<br />다른 이메일을 사용해주세요.");
}
else if (capResult.obj == -3) {
focus("mobile");
msg("이미 사용중인 핸드폰번호입니다.<br />다른 번호를 사용해주세요.");
}
}
window.addEventListener('load', function () { function mobchk() {
if (@Request["jointype"] == "2") { //한번 인증되면 재인증 불가
var naverLogin = new naver.LoginWithNaverId( if ($("#intval2").val() == 1 && $("#mobile").val() != null) {
{ msg("휴대폰 인증이 완료되었습니다.");
clientId: "@naverClientId", } else {
callbackUrl: "https://www.ynicte.com/Account/Join?jointype=2", mobilechkview('MCHK');
isPopup: false, }
callbackHandle: true }
function onGoogleLogIn(googleUser) {
if (@Request["jointype"] == "1") {
var profile = googleUser.getBasicProfile();
$("#username").val(profile.getName());
$("#email").val(profile.getEmail());
$("#snsid").val(profile.getId());
$("#jointype").val(1); //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");
}
}
function snsLogin() {
if (@Request["jointype"] == "2") {
var naverLogin = new naver.LoginWithNaverId(
{
clientId: "@naverClientId",
callbackUrl: "https://www.ynicte.com/Account/Join?jointype=2",
isPopup: false,
callbackHandle: true
}
);
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;
} }
);
naverLogin.init(); $("#username").val(name);
naverLogin.getLoginStatus(function (status) { $("#email").val(email);
if (status) { $("#snsid").val(uniqId);
var email = naverLogin.user.getEmail(); $("#jointype").val(2); //0:일반회원가입,1:google,2:naver,3:kakao
var name = naverLogin.user.getName(); $("#username").prop("readonly", "readonly");
var uniqId = naverLogin.user.getId(); $("#username").css("background-color", "#ddd");
var profileImage = naverLogin.user.getProfileImage(); $("#email").prop("readonly", "readonly");
var birthday = naverLogin.user.getBirthday(); $("#email").css("background-color", "#ddd");
var age = naverLogin.user.getAge(); } else {
if (email == undefined || email == null) { alert("callback 처리에 실패하였습니다. 관리자에게 문의하세요. error status[" + status + "]");
alert("이메일은 필수정보입니다. 정보제공을 동의해주세요."); history.back(-1);
naverLogin.reprompt(); return;
return; }
} });
if (name == undefined || name == null) { }
alert("이름은 필수정보입니다. 정보제공을 동의해주세요."); if (@Request["jointype"] == "3") {
naverLogin.reprompt(); $.when(
return; Kakao.init("@kakaoClientId"),
} ).done(function () {
Kakao.API.request({
$("#username").val(name); url: '/v2/user/me',
$("#email").val(email); success: function (res) {
$("#snsid").val(uniqId); $("#username").val(res.properties.nickname);
$("#jointype").val(2); //0:일반회원가입,1:google,2:naver,3:kakao $("#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").prop("readonly", "readonly");
$("#username").css("background-color", "#ddd"); $("#username").css("background-color", "#ddd");
$("#email").prop("readonly", "readonly"); $("#email").prop("readonly", "readonly");
$("#email").css("background-color", "#ddd"); $("#email").css("background-color", "#ddd");
} else { },
console.log("callback 처리에 실패하였습니다."); fail: function (error) {
console.log(error);
} }
}); });
} });
if (@Request["jointype"] == "3") { }
$.when( }
Kakao.init("@kakaoAppkey"), </script>
).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);
}
});
});
}
});
</script>
}

View File

@ -1,10 +1,12 @@
@{ @{
var naverClientId = "fvaj0CdI04awGMEhaICy"; var naverClientId = ViewBag.naverClientID;
var kakaoAppkey = "7b09519e7bce67d548a2a594a48acf63"; var kakaoClientId = ViewBag.kakaoClientID;
var googleClientId = ViewBag.googleClientID;
} }
<head> <head>
<script type="text/javascript" src="/js/naveridlogin_js_sdk_2.0.0.js"></script> <script type="text/javascript" src="/js/naveridlogin_js_sdk_2.0.0.js"></script>
<script type="text/javascript" src="/js/kakao.js"></script> <script type="text/javascript" src="/js/kakao.js"></script>
<script src="https://apis.google.com/js/platform.js?onload=googleInit" async defer></script>
</head> </head>
<form id="mform" method="post"> <form id="mform" method="post">
<div class="jnSns"> <div class="jnSns">
@ -17,9 +19,10 @@
<li> <li>
<a href="javascript:loginWithKakao()">카카오 아이디로 회원가입</a> <a href="javascript:loginWithKakao()">카카오 아이디로 회원가입</a>
</li> </li>
<li><a href="#">구글 아이디로 회원가입</a></li> <li>
<a href="javascript:loginWithGoogle()">구글 아이디로 회원가입</a>
</li>
</ul> </ul>
<a id="kakao-login-btn"></a>
</div> </div>
</form> </form>
@ -29,6 +32,23 @@
$(document).ready(function () { $(document).ready(function () {
snsInit(); snsInit();
}); });
var gauth;
function googleInit() {
gapi.load('auth2', function () {
var gauth = gapi.auth2.init({
client_id: "@googleClientId",
scope: 'profile'
});
gauth.then(function () {
console.log('google init success');
}, function () {
console.error('google init fail');
})
});
}
var naverLogin = new naver.LoginWithNaverId( var naverLogin = new naver.LoginWithNaverId(
{ {
clientId: "@naverClientId", clientId: "@naverClientId",
@ -39,23 +59,31 @@
); );
function loginWithKakao() { function loginWithKakao() {
Kakao.Auth.login({ Kakao.Auth.login({
success: function (authObj) { success: function (authObj) {
location.href = "https://www.ynicte.com/Account/Join?jointype=3" location.href = "https://www.ynicte.com/Account/Join?jointype=3";
}, },
fail: function (err) { fail: function (err) {
alert("카카오 아이디로 회원가입에 실패했습니다."); alert("카카오 아이디로 회원가입에 실패했습니다.");
console.log(JSON.stringify(err)) console.log(JSON.stringify(err));
}, },
}) })
} }
function loginWithNaver() { function loginWithNaver() {
$("#naverIdLogin_loginButton > img").trigger("click"); $("#naverIdLogin_loginButton > img").trigger("click");
} }
function loginWithGoogle() {
gauth = gapi.auth2.getAuthInstance();
gauth.signIn().then(function () {
//var profile = gauth.currentUser.get().getBasicProfile();
//location.href = "https://www.ynicte.com/Account/Join?jointype=1&gid=" + encodeURI(profile.getId()) + "&gnm=" + encodeURI(profile.getName()) + "&gml=" + encodeURI(profile.getEmail());
location.href = "https://www.ynicte.com/Account/Join?jointype=1";
});
}
function snsInit() { function snsInit() {
naverLogin.init(); naverLogin.init();
Kakao.init("@kakaoAppkey"); Kakao.init("@kakaoClientId");
} }
</script> </script>

View File

@ -1,6 +1,8 @@
@{ @{
Layout = null; Layout = null;
var kakaoAppkey = "7b09519e7bce67d548a2a594a48acf63"; var naverClientId = ViewBag.naverClientID;
var kakaoClientId = ViewBag.kakaoClientID;
var googleClientId = ViewBag.googleClientID;
} }
<head> <head>
@Html.Partial("./Partial/JS") @Html.Partial("./Partial/JS")
@ -10,7 +12,7 @@
var snsid; var snsid;
window.addEventListener('load', function () { window.addEventListener('load', function () {
$.when( $.when(
Kakao.init("@kakaoAppkey") Kakao.init("@kakaoClientId")
).done(function () { ).done(function () {
Kakao.API.request({ Kakao.API.request({
url: '/v2/user/me', url: '/v2/user/me',

View File

@ -1,6 +1,8 @@
@{ @{
Layout = null; Layout = null;
var naverClientId = "fvaj0CdI04awGMEhaICy"; var naverClientId = ViewBag.naverClientID;
var kakaoClientId = ViewBag.kakaoClientID;
var googleClientId = ViewBag.googleClientID;
} }
<head> <head>
<!-- SNS --> <!-- SNS -->