Subversion Repositories SmartDukaan

Rev

Rev 20182 | Rev 20202 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20180 aman.kumar 1
var LoginNamespace={};
2
var authDetails=null;
3
var userDetails=null;
4
/*  window.fbAsyncInit = function() {
7007 amar.kumar 5
    FB.init({
6
      appId      : '${in.shop2020.appId}', // App ID
7
      //channelUrl : '//local.shop2020.in:8080/channel.html', // Channel File
8
      status     : true, // check login status
9
      cookie     : true, // enable cookies to allow the server to access the session
10
      xfbml      : true,  // parse XFBML
11
      oauth  	 : true
12
    });
13
  	};
7020 amar.kumar 14
 
15
  	window.fbAsyncInit();
16
 
7007 amar.kumar 17
  // Load the SDK Asynchronously
18
  (function(d){
19
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
20
     if (d.getElementById(id)) {return;}
21
     js = d.createElement('script'); js.id = id; js.async = true;
22
     js.src = "//connect.facebook.net/en_US/all.js";
23
     ref.parentNode.insertBefore(js, ref);
20180 aman.kumar 24
   }(document));*/
7007 amar.kumar 25
 
20180 aman.kumar 26
/*  function login() {
7007 amar.kumar 27
	    FB.login(function(response) {
28
	    	if (response.authResponse) {
29
	    		authDetails = response.authResponse;
30
	    		FB.api('/me', function(response){
31
	    			  userDetails = response;
32
	    			  if(userDetails!==null) {
33
	    				  loginToSaholicByFacebook(userDetails, authDetails);
34
	  	    		  }
35
	    		});
36
	        } else {
37
	            // cancelled
38
	        }
7825 amar.kumar 39
	    },{scope: 'email, publish_stream'});
20180 aman.kumar 40
  }*/
41
$(document).ready(function() {
42
	  $.ajaxSetup({ cache: true });
43
	  $.getScript('//connect.facebook.net/en_US/sdk.js', function(){
44
	    FB.init({
45
	      appId: '{716370691734306}',
46
	      version: 'v2.7' // or v2.0, v2.1, v2.2, v2.3
47
	    });     
48
	    $('#loginbutton,#feedbutton').removeAttr('disabled');
7007 amar.kumar 49
 
20180 aman.kumar 50
	  });
51
 
52
	(function(d, s, id) {
53
	  var js, fjs = d.getElementsByTagName(s)[0];
54
	  if (d.getElementById(id)) return;
55
	  js = d.createElement(s); js.id = id;
56
	  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7&appId=716370691734306";
57
	  fjs.parentNode.insertBefore(js, fjs);
58
	}(document, 'script', 'facebook-jssdk'));
59
	});
60
 
61
 
7007 amar.kumar 62
  function checkAndCallFacebookLogin() {
7020 amar.kumar 63
	  	//window.fbAsyncInit();
7007 amar.kumar 64
	    FB.getLoginStatus(function(response) {
20180 aman.kumar 65
	  	  // Check login status on load, and if the user is
66
	  	  // already logged in, go directly to the welcome message.
67
	    	authDetails = response;
68
	  	  if (authDetails.status == 'connected') {
69
 
20183 aman.kumar 70
	  		getCurrentUserInfo();
20180 aman.kumar 71
	  	  } else {
72
	  	    // Otherwise, show Login dialog first.
73
	  	    FB.login(function(response) {
74
	  	    	authDetails=response;
20183 aman.kumar 75
	  	    	getCurrentUserInfo();
20180 aman.kumar 76
	  	    }, {scope: 'user_friends, email'});
77
	  	  }
78
	  	});
79
  }
80
 
20183 aman.kumar 81
 
20180 aman.kumar 82
	function getCurrentUserInfo() {
83
	      FB.api('/me?fields=id,name,email,permissions', function(userInfo) {
84
	    	  userDetails = userInfo;
20183 aman.kumar 85
	    	  if(authDetails && authDetails.status=='connected' && userDetails && userDetails.email){
86
	  			$.ajax({
87
	  				type : "POST",
88
	  				url : "/login!verifyFbUser?accessToken="+authDetails.authResponse.accessToken+"&email="+userDetails.email,
89
	  				success : function(response) {
90
	  					response = JSON.parse(response);
91
	  					if(response.status=='success')
92
	  						window.location.href="http://www.shop2020.in";
93
	  					else
94
	  						alert(response.message);
95
	  				}
96
 
97
	  			});
98
	  	  }else{
99
	  		  //retry
100
	  		  //login unsuccessful
101
	  	  }
20180 aman.kumar 102
	      });
103
	    }
104
 
105
 
106
	function updateStatusCallback(response){
107
	console.log(response);
108
	FB.getLoginStatus(function(response){console.log(response)});
109
 
110
	getCurrentUserInfo();
111
/*	$.ajax({
112
						type : "POST",
113
						url : "/login/?email=acad.amitgupta@gmail.com&name=Amit&gender=male&isFacebookUser=true&accessToken=",
114
						success : function(response) {
115
							window.location = "/";
116
						}
117
					});*/
118
	}
119