Subversion Repositories SmartDukaan

Rev

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

Rev 20183 Rev 20202
Line 1... Line 1...
1
var LoginNamespace={};
1
var LoginNamespace={};
2
var authDetails=null;
2
var authDetails=null;
3
var userDetails=null;
3
var userDetails=null;
4
/*  window.fbAsyncInit = function() {
-
 
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
  	};
-
 
14
  	
-
 
15
  	window.fbAsyncInit();
-
 
16
  	
-
 
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);
-
 
24
   }(document));*/
-
 
25
  
4
 
26
/*  function login() {
-
 
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
	        }
-
 
39
	    },{scope: 'email, publish_stream'});
-
 
40
  }*/
-
 
41
$(document).ready(function() {
5
$(document).ready(function() {
42
	  $.ajaxSetup({ cache: true });
6
	  $.ajaxSetup({ cache: true });
43
	  $.getScript('//connect.facebook.net/en_US/sdk.js', function(){
7
	  $.getScript('//connect.facebook.net/en_US/sdk.js', function(){
44
	    FB.init({
8
	    FB.init({
45
	      appId: '{716370691734306}',
9
	      appId: '{716370691734306}',
Line 56... Line 20...
56
	  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7&appId=716370691734306";
20
	  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7&appId=716370691734306";
57
	  fjs.parentNode.insertBefore(js, fjs);
21
	  fjs.parentNode.insertBefore(js, fjs);
58
	}(document, 'script', 'facebook-jssdk'));
22
	}(document, 'script', 'facebook-jssdk'));
59
	});
23
	});
60
 
24
 
61
 
25
var mode = '';
62
  function checkAndCallFacebookLogin() {
26
  function checkAndCallFacebookLogin() {
-
 
27
	  mode = $('#loginText').html();
-
 
28
	  $('#errormessage').hide();
-
 
29
	  $('#errormessage').html('');
63
	  	//window.fbAsyncInit();
30
	  	//window.fbAsyncInit();
64
	    FB.getLoginStatus(function(response) {
31
	    FB.getLoginStatus(function(response) {
65
	  	  // Check login status on load, and if the user is
32
	  	  // Check login status on load, and if the user is
66
	  	  // already logged in, go directly to the welcome message.
33
	  	  // already logged in, go directly to the welcome message.
67
	    	authDetails = response;
34
	    	authDetails = response;
Line 76... Line 43...
76
	  	    }, {scope: 'user_friends, email'});
43
	  	    }, {scope: 'user_friends, email'});
77
	  	  }
44
	  	  }
78
	  	});
45
	  	});
79
  }
46
  }
80
  
47
  
-
 
48
  function loginregister(){
-
 
49
	  mode = $('#loginText').html();
-
 
50
	  $('#errormessage').hide();
-
 
51
	  $('#errormessage').html('');
-
 
52
	  if(mode =='Login'){
-
 
53
		  $.ajax({
-
 
54
				type : "POST",
-
 
55
				url : "/login?email="+$('#email').val()+"&password="+$('#password').val(),
-
 
56
				success : function(response) {
-
 
57
					response = JSON.parse(response);
-
 
58
					if(response.status=='success'){
-
 
59
						window.location.reload();
-
 
60
					}else{
-
 
61
						$('#errormessage').html(response.message);
-
 
62
					$('#errormessage').show();
-
 
63
					}
-
 
64
					
-
 
65
				}
-
 
66
			});
-
 
67
	  }else{
-
 
68
		  $.ajax({
-
 
69
				type : "POST",
-
 
70
				url : "/register?redirectUrl=/&email="+$('#email').val()+"&password="+$('#password').val(),
-
 
71
				success : function(response) {
-
 
72
					response = JSON.parse(response);
-
 
73
					if(response.status=='success'){
-
 
74
						window.location.reload();
-
 
75
					}else{
-
 
76
						$('#errormessage').html(response.message);
-
 
77
					$('#errormessage').show();
-
 
78
					}
-
 
79
				}
-
 
80
			});
-
 
81
	  }
-
 
82
  }
-
 
83
  
81
 
84
 
82
	function getCurrentUserInfo() {
85
	function getCurrentUserInfo() {
83
	      FB.api('/me?fields=id,name,email,permissions', function(userInfo) {
86
	      FB.api('/me?fields=id,name,email,permissions', function(userInfo) {
84
	    	  userDetails = userInfo;
87
	    	  userDetails = userInfo;
85
	    	  if(authDetails && authDetails.status=='connected' && userDetails && userDetails.email){
88
	    	  if(authDetails && authDetails.status=='connected' && userDetails && userDetails.email){
-
 
89
	  			if(mode=='Login'){
86
	  			$.ajax({
90
	    		  $.ajax({
87
	  				type : "POST",
91
	  				type : "POST",
88
	  				url : "/login!verifyFbUser?accessToken="+authDetails.authResponse.accessToken+"&email="+userDetails.email,
92
	  				url : "/login!verifyFbUser?accessToken="+authDetails.authResponse.accessToken+"&email="+userDetails.email,
89
	  				success : function(response) {
93
	  				success : function(response) {
90
	  					response = JSON.parse(response);
94
	  					response = JSON.parse(response);
91
	  					if(response.status=='success')
95
	  					if(response.status=='success'){
92
	  						window.location.href="http://www.shop2020.in";
96
	  						window.location.reload();
93
	  					else
97
	  					}else{
94
	  						alert(response.message);
98
	  						$('#errormessage').html(response.message);
-
 
99
	  						$('#errormessage').show();
-
 
100
	  					}
95
	  				}
101
	  				}
96
	  				
-
 
97
	  			});
102
	  			});
-
 
103
	  			}else{
-
 
104
	  				$.ajax({
-
 
105
		  				type : "POST",
-
 
106
		  				url : "/login!signupFacebookUser?accessToken="+authDetails.authResponse.accessToken+"&email="+userDetails.email,
-
 
107
		  				success : function(response) {
-
 
108
		  					response = JSON.parse(response);
-
 
109
		  					if(response.status=='success'){
-
 
110
		  						window.location.reload();
-
 
111
		  					}else{
-
 
112
		  						$('#errormessage').html(response.message);
-
 
113
		  						$('#errormessage').show();
-
 
114
		  					}
-
 
115
		  				}
-
 
116
		  				
-
 
117
		  			});
-
 
118
	  			}
-
 
119
	  			
-
 
120
	  			
98
	  	  }else{
121
	  	  }else{
99
	  		  //retry
122
	  		  //retry
100
	  		  //login unsuccessful
123
	  		  //login unsuccessful
101
	  	  }
124
	  	  }
102
	      });
125
	      });
103
	    }
126
	    }
104
  
127
  
105
 
128
 
-
 
129
	
106
	function updateStatusCallback(response){
130
		function openpopup(){
-
 
131
			$('#register-login-popup').show();
-
 
132
			toggleLoginRegisterView('login');
-
 
133
		}
-
 
134
 
107
	console.log(response);
135
		function closepopup(){
-
 
136
		$('#register-login-popup').hide();
108
	FB.getLoginStatus(function(response){console.log(response)});
137
		toggleLoginRegisterView('login');
-
 
138
		}
109
 
139
 
-
 
140
		function toggleLoginRegisterView(view){
110
	getCurrentUserInfo();
141
			$('#errormessage').hide();
-
 
142
			$('#email').html('');
-
 
143
			$('#password').html('');
-
 
144
			$('#errormessage').html('');
-
 
145
			
-
 
146
		if(view=='register'){
-
 
147
		$('#registerlogin').html('REGISTER');
-
 
148
		$('#loginText').html('Register');
-
 
149
		$('#loginregistertext').html('Already a member? <a href="javascript: void(0);" style="color:#069" onclick="toggleLoginRegisterView(\'login\')">Login</a></div>');
-
 
150
		$('#forgotPassword').hide();
111
/*	$.ajax({
151
		}else{
-
 
152
		$('#registerlogin').html('LOGIN');
-
 
153
		$('#loginText').html('Login');
-
 
154
		$('#loginregistertext').html('Do not have an account?<a href="javascript: void(0);" style="color:#069" onclick="toggleLoginRegisterView(\'register\')">Register</a></div>');
-
 
155
		$('#forgotPassword').show();
-
 
156
		}
-
 
157
		}
-
 
158
	
112
						type : "POST",
159
	function loginsignup(){
-
 
160
		if($('#register-login-popup').length==0){
113
						url : "/login/?email=acad.amitgupta@gmail.com&name=Amit&gender=male&isFacebookUser=true&accessToken=",
161
			$('<html><style>#register-login-popup{width:100%;height:100%;position:fixed;top:0;left:0;background:rgba(102,102,102,.55)}.login-container{margin:0 auto;width:740px;z-index:10;height:auto;top:40px;position:relative;background:0 0}.login-inner-container{z-index:95;width:660px;min-height:400px;left:0;right:0;top:0;margin:auto;height:auto;background:#fff;position:relative}div.wrap{width:250px;margin-left:45px}div.wrap div{position:relative;margin:20px 0}.label{position:absolute;top:0;font-size:16px;margin:25px 25px 25px -5px;color:grey;padding:0 10px;background-color:#fff;-webkit-transition:top .2s ease-in-out,font-size .2s ease-in-out;transition:top .2s ease-in-out,font-size .2s ease-in-out}.active{top:-30px;font-size:20px;color:#069}div.wrap input{width:100%;padding:20px 20px 5px 5px;border:none;border-bottom:1px solid grey;font-size:20px;background-color:transparent;color:grey;position:relative;outline:0}div.wrap input:focus{border-color:#069;font-size:16px;-webkit-transition:border-color .15s ease-in-out 0s,box-shadow .15s ease-in-out 0s;transition:border-color .15s ease-in-out 0s,box-shadow .15s ease-in-out 0s}#loginBtn{cursor:pointer;border-radius:5px;width:250px;background-color:#069;padding:5 0;border:2px solid #069;text-align:center;margin-top:40px}#loginBtn:hover{border-color:grey;-webkit-transition:border-color .15s ease-in-out 0s,box-shadow .15s ease-in-out 0s;transition:border-color .15s ease-in-out 0s,box-shadow .15s ease-in-out 0s}#loginText{font-size:24px;color:#fff;margin:10px 0}</style><script src="http://code.jquery.com/jquery-2.1.1.min.js" ></script><div id="register-login-popup" style="display:none"> <div id="iframeContainer" class="login-container"> <div class="login-inner-container"> <div onclick="closepopup()" id="closepopup" style="background-color: #333232;color: #fff;font-size: 24px;padding: 8px;position: absolute;right: -33px;cursor: pointer;">X</div><div style="height:10px;width:100%;margin:0 auto;padding:5px"></div><div id="registerlogin" style="width:100%;margin:0 auto;text-align: center;color:#069;float:left;padding-bottom:5px;font-size:26px;"> LOGIN </div><div style="width:100%;margin:0 auto;text-align: center;float: left;margin-top: 2px;"> <div style="width: 50%;height:auto;background-color: white;float:left;"> <div id="loginCreate" class="register-login" > <div id="errormessage" style="width:100%;text-align:center;font-size:12px;color:red;display:none"> email/password is wrong</div><div class="wrap"> <div> <label class="label" >Email</label> <input id="email" name="email" type="text" autocomplete = "off" class="cool"/> </div><div> <label class="label" >Password</label> <input id="password" name="password" autocomplete="off" type="password" class="cool"/> </div><div id="forgotPassword" style="margin: 0px;margin-top: -19px;margin-right: -162px;font-size: 12px;font-style: italic;"> <a href="/forgot-password" style="color:#069">forgot password?</a></div><div class="loginBtn" id="loginBtn" onclick="loginregister()"> <div id="loginText" > Login </div></div><div id="loginregistertext" style="width:100%;text-align:center;font-size:14px;font-weight:bold;"> Do not have an account? <a href="javascript: void(0);" style="color:#069" onclick="toggleLoginRegisterView(\'register\')">Register</a></div></div></div></div><div style="width:1px;height:300px;background-color: white;float: left;border-left: 1px solid grey;margin-top: 7px;margin-left: 3px;"></div><div style="width: 48%;height:300px;background-color: white;float:right;text-align:center;"><div style="width: 100%;font-size: 23px;color: #069;margin-top: 17px;"> Or Try </div><div onclick="checkAndCallFacebookLogin()" style="text-align:right;background: url(\'images/facebookconnect.png\');background-repeat: no-repeat;height: 42px;background-size: 250px 43px;margin-top: 162px;border-radius: 5px;width: 250px;margin-left: 29px;"><div id="fbloginbtn" style="color:white;font-weight:bold;font-size: 16px;padding: 8px;padding-top: 12px;">Connect with Facebook</div></div></div></div></div></div></div></div></html>').insertAfter('#footer');
-
 
162
			$(document).ready(function(){
114
						success : function(response) {
163
				$('input').focusin( function() {
-
 
164
				  $(this).parent().find('label').addClass('active');
-
 
165
				 
-
 
166
				});
-
 
167
 
115
							window.location = "/";
168
				$('input').focusout( function() {
-
 
169
				  if (!this.value) {
-
 
170
				    $(this).parent().find('label').removeClass('active');
-
 
171
 
116
						}
172
				  }
-
 
173
				});
-
 
174
				
117
					});*/
175
				});
-
 
176
			
-
 
177
			openpopup();
-
 
178
			
-
 
179
		}
118
	}
180
	}
119
 
181