Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.fbAsyncInit = function () {
- FB.init({
- appId: '672221882789824', // App ID
- channelUrl: '//'+ gameForestIP +':46069/channel.html',
- status: true, // check login status
- cookie: true, // enable cookies to allow the server to access the session
- xfbml: true // parse XFBML
- });
- // Initialize when a user has authenticated with FB and this app
- // Handle events accordingly
- FB.Event.subscribe('auth.authResponseChange', function (response) {
- if (response.status === 'connected') {
- // user is logged in to FB
- // has authorized app
- console.log('Welcome, fetching information');
- FB.api('/me', function (response) {
- var fbid = response.id;
- var fbuser = response.username;
- var fname = response.first_name;
- var lname = response.last_name;
- var request = $.ajax({
- url: "http://"+ gameForestIP +":1193/service/user/fb?fbid=" + fbid + "&username=" + fbuser + "&firstname=" + fname + "&lastname=" + lname,
- async: true,
- type: "POST"
- });
- request.done(function (msg) {
- if (msg.ResponseType != 0) {
- // show error (maybe in an error div?)
- $("#alertDialog").show();
- $("#alertDialog").html("<p class='glyphicon glyphicon-warning-sign' style='margin-right:10px'/>" + msg.AdditionalData);
- }
- else {
- // store session ID to local storage
- localStorage.setItem("user-session", msg.AdditionalData);
- console.log("sessionid: " + localStorage.getItem("user-session"));
- }
- $("buttonSignIn").button('reset');
- $("#fbLogout").show();
- $("#linkLogout").hide();
- });
- request.fail(function (nothing, textStatus, something) {
- $("#alertDialog").show();
- $("#alertDialog").css("class", "alert alert-danger");
- $("#alertDialog").html("<p class='glyphicon glyphicon-warning-sign' style='margin-right:10px'/>" + "Something went wrong! :(");
- $("buttonSignIn").button('reset');
- });
- $("#login-well").hide();
- $("#userinfo-well").show();
- document.getElementById('fb-log-well').style.display = 'none';
- })
- // -------------------- LOGOUT --------------------------
- document.getElementById('fbLogout').addEventListener('click', function () {
- var request = $.ajax({
- url: "http://"+ gameForestIP + ":1193/service/user/login?usersessionid=" + localStorage.getItem("user-session"),
- async: true,
- type: "DELETE"
- });
- request.success(function (data) {
- if (data.ResponseType != 0) {
- // hehe, this is imposible...
- }
- else {
- FB.logout(function () {
- // wipe user
- window.location.reload(true);
- });
- }
- });
- });
- // ---------------- END LOGOUT -----------------------------
- } else if (response.status === 'not_authorized') {
- // user is logged in to FB
- // has not authorized app
- document.getElementById('fb-log-well').style.display = 'block';
- } else {
- // user is not logged in to FB
- // has not authorized app
- document.getElementById('fb-log-well').style.display = 'block';
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment