Last active
February 24, 2016 10:38
-
-
Save kimyongin/0c3693c03181bb6cbba6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function kakaoLogin(callback) { | |
// 소셜 로그인창을 띄운다 | |
Kakao.Auth.login({ | |
success: function (authObj) { | |
// 소셜 로그인 성공 | |
Kakao.API.request({ | |
url: '/v1/user/me', | |
success: function (response) { | |
// 소셜 정보 가져오기 | |
var userName = response.properties.nickname; | |
var userId = response.id; | |
// 소셜ID로 로컬 로그인 | |
localLogin({ userId: userId }, function (response, data) { | |
if (response.status == 200) { | |
// 로컬 로그인 성공 | |
callback(response, data); | |
} else { | |
// 로컬 로그인 실패 (--> 소셜로그인을 처음한 경우) | |
// 로컬 가입 | |
localSignup( | |
{ | |
type: "kakao", | |
userId: userId, | |
userData: { userName: userName } | |
}, callback); | |
} | |
}); | |
}, | |
fail: function (error) { | |
alert(JSON.stringify(error)) | |
} | |
}); | |
}, | |
fail: function (err) { | |
alert(JSON.stringify(err)) | |
} | |
}); | |
} | |
// ------------------------------------- | |
kakaoLogin(function (response, data) { | |
if (response.status == 200) { | |
toastr.success(data, 'Welcome'); | |
$uibModalInstance.close(); | |
} else { | |
toastr.error(data, "Login Failed"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment