Subversion Repositories SmartDukaan

Rev

Rev 7825 | Rev 20181 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7825 Rev 20180
Line -... Line 1...
-
 
1
var LoginNamespace={};
1
var userDetails = null;
2
var authDetails=null;
2
var authDetails = null;
3
var userDetails=null;
3
 
-
 
4
  window.fbAsyncInit = function() {
4
/*  window.fbAsyncInit = function() {
5
    FB.init({
5
    FB.init({
6
      appId      : '${in.shop2020.appId}', // App ID
6
      appId      : '${in.shop2020.appId}', // App ID
7
      //channelUrl : '//local.shop2020.in:8080/channel.html', // Channel File
7
      //channelUrl : '//local.shop2020.in:8080/channel.html', // Channel File
8
      status     : true, // check login status
8
      status     : true, // check login status
9
      cookie     : true, // enable cookies to allow the server to access the session
9
      cookie     : true, // enable cookies to allow the server to access the session
Line 19... Line 19...
19
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
19
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
20
     if (d.getElementById(id)) {return;}
20
     if (d.getElementById(id)) {return;}
21
     js = d.createElement('script'); js.id = id; js.async = true;
21
     js = d.createElement('script'); js.id = id; js.async = true;
22
     js.src = "//connect.facebook.net/en_US/all.js";
22
     js.src = "//connect.facebook.net/en_US/all.js";
23
     ref.parentNode.insertBefore(js, ref);
23
     ref.parentNode.insertBefore(js, ref);
24
   }(document));
24
   }(document));*/
25
  
25
  
26
  function login() {
26
/*  function login() {
27
	    FB.login(function(response) {
27
	    FB.login(function(response) {
28
	    	if (response.authResponse) {
28
	    	if (response.authResponse) {
29
	    		authDetails = response.authResponse;
29
	    		authDetails = response.authResponse;
30
	    		FB.api('/me', function(response){
30
	    		FB.api('/me', function(response){
31
	    			  userDetails = response;
31
	    			  userDetails = response;
Line 35... Line 35...
35
	    		});
35
	    		});
36
	        } else {
36
	        } else {
37
	            // cancelled
37
	            // cancelled
38
	        }
38
	        }
39
	    },{scope: 'email, publish_stream'});
39
	    },{scope: 'email, publish_stream'});
40
  }
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');
-
 
49
 
-
 
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
 
41
 
61
 
42
  function checkAndCallFacebookLogin() {
62
  function checkAndCallFacebookLogin() {
43
	  	//window.fbAsyncInit();
63
	  	//window.fbAsyncInit();
44
	    FB.getLoginStatus(function(response) {
64
	    FB.getLoginStatus(function(response) {
45
	    	  if (response.status === 'connected') {
-
 
46
	    		  FB.api('/me', function(response){
-
 
47
	    			  userDetails = response;
-
 
48
	    			  if(userDetails!==null) {
-
 
49
	  	    			loginToSaholicByFacebook(userDetails, authDetails);
-
 
50
	  	    		  }
-
 
51
	    		  });
-
 
52
	    	  } else if (response.status === 'not_authorized') {
-
 
53
	    		  login();
-
 
54
	    	  } else {
-
 
55
	    		  login();
-
 
56
	    	  }
-
 
57
	    });
-
 
58
  }
-
 
59
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
	  		  
-
 
70
	  		checkResponse();
-
 
71
	  	  } else {
-
 
72
	  	    // Otherwise, show Login dialog first.
-
 
73
	  	    FB.login(function(response) {
-
 
74
	  	    	authDetails=response;
-
 
75
	  	      checkResponse();
-
 
76
	  	    }, {scope: 'user_friends, email'});
-
 
77
	  	  }
-
 
78
	  	});
-
 
79
  }
-
 
80
  
-
 
81
  function checkResponse(){
-
 
82
	  getgetCurrentUserInfo()
-
 
83
	  if(authDetails && authDetails.status=='connected' && userDetails && userDetails.email){
-
 
84
			$.ajax({
-
 
85
				type : "POST",
-
 
86
				url : "/login!verifyFbUser?accessToken="+response.accessToken+"&email="+userDetails.email,
-
 
87
				success : function(response) {
-
 
88
					if(response.status=='success')
-
 
89
						window.location.href="http://www.shop2020.in";
-
 
90
					else
-
 
91
						alert(response.message);
-
 
92
				}
-
 
93
				
-
 
94
			});
-
 
95
	  }else{
-
 
96
		  //retry
-
 
97
		  //login unsuccessful
-
 
98
	  }
-
 
99
  }
-
 
100
  
-
 
101
	function getCurrentUserInfo() {
-
 
102
	      FB.api('/me?fields=id,name,email,permissions', function(userInfo) {
-
 
103
	    	  userDetails = userInfo;
-
 
104
	      });
-
 
105
	    }
-
 
106
  
-
 
107
 
-
 
108
	function updateStatusCallback(response){
-
 
109
	console.log(response);
-
 
110
	FB.getLoginStatus(function(response){console.log(response)});
-
 
111
 
-
 
112
	getCurrentUserInfo();
-
 
113
/*	$.ajax({
-
 
114
						type : "POST",
-
 
115
						url : "/login/?email=acad.amitgupta@gmail.com&name=Amit&gender=male&isFacebookUser=true&accessToken=",
-
 
116
						success : function(response) {
-
 
117
							window.location = "/";
-
 
118
						}
-
 
119
					});*/
-
 
120
	}
-
 
121
 
-
 
122