//THIS FILE IS DEPRECATED AND NOT USED ANYMORE window.fbAsyncInit = function() { FB.init({ appId: '1490794814472224', status: false, // check login status cookie: true, // enable cookies to allow the server to access the session xfbml: true // parse XFBML }); // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired // for any authentication related change, such as login, logout or session refresh. This means that // whenever someone who was previously logged out tries to log in again, the correct case below // will be handled. //BORTKLIPP HÄR }; function loginFacebookUser(response) { var resp = response; var userid = response.authResponse.userID; if (response.status === 'connected') { $.ajax({ type: "POST", url: "/common/ajax/loginFacebookUser", dataType: 'json', data: { userid: userid }, success: function(data) { if (data.userid && data.success === true && data.closed === true) { //login successful, but user is closed window.location = "/common/login?digest="+data.digest; } else if (data.userid && data.success === true && data.closed === false) { //login successful, return to source window.location = "/common/login?digest="+data.digest; } else { //user does not exist in database, register it alert('Redan medlem? Logga in med användarnamn och lösenord. Ny medlem? Klicka egistrera med Facebook i den gula rutan.'); } }, error: function(jqXHR, textStatus, errorThrown) { alert("Fel: " + textStatus + "," + errorThrown); } }); } } function registerFacebookUser(response) { var userid = response.authResponse.userID; $("#facebookLogin").addClass("hidden"); $("#facebookLoginLoading").removeClass("hidden"); FB.login(function (response) { if(response.status==="connected") { console.log("Login OK"); FB.api('/me?fields=first_name,last_name,email,birthday,gender', function(response) { console.log("Response from FB: " + response); if (response.first_name) { console.log("Nya metoden! ID " + userid + "\nFörnamn " + response.first_name + "\nE-post " + response.email + "\nÅlder " + response.birthday + "\nKön " + response.gender); if(response.email) { //all should be ok, just register console.log("All fine, just register!"); saveFacebookUser(userid, response.first_name, response.last_name, response.email, response.birthday, response.gender); }else { console.log("Some data missing, push to form!"); pushFacebookDataToForm(userid, response.first_name, response.last_name, response.email, response.gender, response.birthday); alert("Du behöver komplettera viss data, fyll i formuläret nedan"); $("#facebookLogin").removeClass("hidden"); $("#facebookLoginLoading").addClass("hidden"); } } else { alert("Användardata kunde inte hämtas. Vänligen försök igen."); console.log("Nya metoden! ID " + userid + "\nFörnamn " + response.first_name + "\nE-post " + response.email + "\nÅlder " + response.birthday + "\nKön " + response.gender); $("#facebookLogin").removeClass("hidden"); $("#facebookLoginLoading").addClass("hidden"); } }); }else { console.log("Login failed for response: " + response +"\n\nResponse status: "+response.status); } },{ scope: 'email,user_birthday' }); /* perms changed to scope */ } function saveFacebookUser(facebookUserId, firstName, lastName, email, birthday, gender) { $.ajax({ type: "POST", url: "/common/ajax/registerFacebookUser", data: {facebookUserId: facebookUserId, firstName: firstName, lastName: lastName, email: email, dateOfBirth: birthday, sex: gender}, dataType : "json", success: function(data) { if (data.success) { window.location = "/common/login?digest=" + data.digest; } else { alert("Registrering av användare misslyckades.\n\n" + data.message); $("#facebookLogin").removeClass("hidden"); $("#facebookLoginLoading").addClass("hidden"); } }, error: function(jqXHR, textStatus, errorThrown) { alert("Redan medlem? Logga in med användarnamn och lösenord. Ny medlem? Klicka egistrera med Facebook i den gula rutan." + textStatus); } }); } function hideLoginButton() { $('.hide-to-login').hide(); $('.hide-to-logout').show(); } // Load the SDK asynchronously (function(d) { 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.js"; ref.parentNode.insertBefore(js, ref); }(document));