Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

var userDetails = null;
var authDetails = null;

  window.fbAsyncInit = function() {
    FB.init({
      appId      : '${in.shop2020.appId}', // App ID
      //channelUrl : '//local.shop2020.in:8080/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true,  // parse XFBML
      oauth      : true
    });
        };
        
        window.fbAsyncInit();
        
  // 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));
  
  function login() {
            FB.login(function(response) {
                if (response.authResponse) {
                        authDetails = response.authResponse;
                        FB.api('/me', function(response){
                                  userDetails = response;
                                  if(userDetails!==null) {
                                          loginToSaholicByFacebook(userDetails, authDetails);
                                  }
                        });
                } else {
                    // cancelled
                }
            },{scope: 'email'});
  }

  function checkAndCallFacebookLogin() {
                //window.fbAsyncInit();
            FB.getLoginStatus(function(response) {
                  if (response.status === 'connected') {
                          FB.api('/me', function(response){
                                  userDetails = response;
                                  if(userDetails!==null) {
                                        loginToSaholicByFacebook(userDetails, authDetails);
                                  }
                          });
                  } else if (response.status === 'not_authorized') {
                          login();
                  } else {
                          login();
                  }
            });
  }