Created
September 30, 2013 03:26
-
-
Save jtubert/6759029 to your computer and use it in GitHub Desktop.
Sketchio presentation - login
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
Parse.initialize(KEY, SECRET); | |
window.fbAsyncInit = function() { | |
// init the FB JS SDK | |
Parse.FacebookUtils.init({ | |
appId : '1386686244890246', // App ID from the app dashboard | |
channelUrl : 'channel.html', // Channel file for x-domain comms | |
status : false, // check login status | |
cookie : true, // enable cookies to allow Parse to access the session | |
xfbml : true // parse XFBML | |
}); | |
}; | |
(function(d, debug){ | |
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; | |
if (d.getElementById(id)) {return;} | |
js = d.createElement('script'); js.id = id; js.async = true; | |
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js"; | |
ref.parentNode.insertBefore(js, ref); | |
}(document, /*debug*/ false)); | |
$('#signin').click(function (e) { | |
Parse.FacebookUtils.logIn(null, { | |
success: function (user) { | |
// If it's a new user, let's fetch their name from FB | |
if (!user.existed()) { | |
// We make a graph request | |
FB.api('/me', function (response) { | |
if (!response.error) { | |
// We save the data on the Parse user | |
user.set("displayName", response.name); | |
user.save(null, { | |
success: function (user) { | |
// And finally save the new score | |
that.navigateToListPage(); | |
}, | |
error: function (user, error) { | |
console.log("Oops, something went wrong saving your name."); | |
} | |
}); | |
} else { | |
console.log("Oops something went wrong with facebook."); | |
} | |
}); | |
// If it's an existing user that was logged in, we save the score | |
} else { | |
FB.api('/me', function (response) { | |
if (!response.error) { | |
//console.log(response.name); | |
$('.logout').text(response.name + " - logout"); | |
} | |
}); | |
that.navigateToListPage(); | |
} | |
}, | |
error: function (user, error) { | |
console.log("Oops, something went wrong."); | |
} | |
}); | |
return false; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment