Created
August 23, 2013 08:12
-
-
Save Satshabad/6316759 to your computer and use it in GitHub Desktop.
This took me a while
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 isLoggedIn() { | |
var deferred = $q.defer(); | |
Facebook.getLoginStatus().then(function(loginStatus) { | |
if (!loginStatus.loggedIn) { | |
resolve(deferred, false); | |
} else { | |
user.accessToken = loginStatus.authResponse.accessToken; | |
user.id = loginStatus.authResponse.userID | |
var tryToGetMe = Facebook.api('/me'), | |
tryToGetPic = Facebook.api('/me/picture'); | |
$q.all([tryToGetMe, tryToGetPic]).then(function(results) { | |
var me = results[0], | |
pic = results[1]; | |
user.fullName = me.first_name + " " + me.last_name; | |
user.picture = pic.data.url; | |
// This is passed to the next "then" function | |
return { | |
"accessToken" : user.accessToken, | |
"fbId" : user.id, | |
"fullName" : user.fullName, | |
"imageLink" : user.picture | |
}; | |
}).then(function(postParams) { | |
var tryToLogin = $http.post('http://localhost:8000/login', postParams) | |
tryToLogin.then(function(response) { | |
resolve(deferred, response.status === 200); | |
}); | |
}) | |
} | |
}); | |
return deferred.promise | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment