window.fbAsyncInit = function() { FB.init({ appId : '138620579524161', // App ID channelURL : '//onenews.com/channel.php', // Channel File status : true, // check login status cookie : true, // enable cookies to allow the server to access the session oauth : true, // enable OAuth 2.0 xfbml : true // parse XFBML }); // Additional initialization code here }; var fbdata = new Object(); function fblogin() { FB.login(function(response) { if(response.authResponse) { var fbdata = new Object(); var __this = this; FB.api('/me', function(response) { __this.fbdata.auth_type = 'facebook'; __this.fbdata.social_id = response.id; __this.fbdata.email = response.email; __this.fbdata.first_name = response.first_name; __this.fbdata.last_name = response.last_name; __this.fbdata.username = response.username; $.post('/index.php/Profiles_c/login_social_account', __this.fbdata, function(data) { if(data == 'true') { /** social account exists, redirect to dashbaord **/ window.location = '/index.php/Webinterface_c/rep_dashboard'; //console.log(data); } else { /** social account doesn't exist proceed with registration **/ FB.api('/me/interests', function(response) { var interests = new Array(); for(interest in response.data) interests[interests.length] = response.data[interest].name; __this.fbdata.interests = interests.join(','); FB.api('/me/activities', function(response) { var activities = new Array(); for(activity in response.data) activities[activities.length] = response.data[activity].name; __this.fbdata.activities = activities.join(','); FB.api('/me/groups', function(response) { var groups = new Array(); for(group in response.data) groups[groups.length] = response.data[group].name; __this.fbdata.affiliations = groups.join(','); /** gathered all FB data, redirect to registration completion **/ //var url = "http://"+window.location.host+"/tmpreg/finish_reg.php?auth_type=facebook" + // "&email="+__this.fbdata.email+ // "&firstname="+__this.fbdata.first_name+ // "&lastname="+__this.fbdata.last_name+ // "&interests="+__this.fbdata.interests+ // "&activities="+__this.fbdata.activites+ // "&affiliations="+__this.fbdata.affiliations+ // "&social_id="+__this.fbdata.social_id; $('#fbauth_type').val('facebook'); $('#fbemail').val(__this.fbdata.email); $('#fbfirst_name').val(__this.fbdata.first_name); $('#fblast_name').val(__this.fbdata.last_name); $('#fbinterests').val(__this.fbdata.interests); $('#fbactivities').val(__this.fbdata.activities); $('#fbaffiliations').val(__this.fbdata.affiliations); $('#fbsocial_id').val(__this.fbdata.social_id); if(undefined != __this.fbdata.username) $('#fbusername').val(__this.fbdata.username); $('#fbreg').submit(); //if(undefined != __this.fbdata.username) url = url+"&username="+__this.fbdata.username; //window.location = url; }); }); }); } }); }); } else { console.log('user did not authenticate'); } }, {scope: 'email,user_location,user_interests,user_activities,user_groups,offline_access'}); } function login_fb() { FB.login(function(response) { if(response.authResponse) { //user info var fbdata = new Object(); var __this = this; FB.api('/me', function(response) { console.log(response); __this.fbdata.fbid = response.id; __this.fbdata.email = response.email; __this.fbdata.first_name = response.first_name; __this.fbdata.last_name = response.last_name; __this.fbdata.username = response.username; //__this.fbdata.token = response.session.access_token; //user interests FB.api('/me/interests', function(response) { var interests = new Array(); for(interest in response.data) interests[interests.length] = response.data[interest].name; __this.fbdata.interests = interests.join(','); //user activities FB.api('/me/activities', function(response) { var activities = new Array(); for(activity in response.data) activities[activities.length] = response.data[activity].name; __this.fbdata.activities = activities.join(','); //user groups FB.api('/me/groups', function(response) { var groups = new Array(); for(group in response.data) groups[groups.length] = response.data[group].name; __this.fbdata.groups = groups.join(','); var url = 'http://develop.sweneno.com/tmpreg/finish_reg.php?auth_type=facebook&email='+__this.fbdata.email+'&firstname='+__this.fbdata.first_name+'&lastname='+__this.fbdata.last_name+'&interests='+__this.fbdata.interests+'&activities='+__this.fbdata.activities+'&affiliations='+__this.fbdata.groups+'&social_id='+__this.fbdata.fbid; if(undefined != __this.fbdata.username) url = url+'&username='+__this.fbdata.username; window.location = url; //console.log(__this.fbdata); /*$.post('/index.php/Profiles_c/process_registration_new_reporter', __this.fbdata, function(data) { $('#result').html(data); if(data == 5) { window.location = '/index.php/Profiles_c'; } else if(data == 1) { window.location = '/index.php/Profiles_c'; } else { console.log('unable to login with fb'); //alert('unable to login with fb'); } });*/ //FB.logout(function(response) { }); }); }); }); }); } else { console.log('User cancelled login or did not fully authorize.'); } }, {scope: 'email,user_location,user_interests,user_activities,user_groups,offline_access'}); } // Load the SDK Asynchronously (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document));