Subversion Repositories SmartDukaan

Rev

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

Rev 23343 Rev 24383
Line 1... Line 1...
1
var googleProfile;
1
var googleProfile;
-
 
2
var partnerName;
-
 
3
$(function() {
2
 
4
 
-
 
5
	$(".login").live('click', function() {
-
 
6
		console.log("Login DashBoard");
-
 
7
		var emailIdOrMobileNumber = $("#emailormobile").val();
-
 
8
		console.log(emailormobile);
-
 
9
		var password = $("input[type='password']").val();
-
 
10
		if (emailIdOrMobileNumber == "" || emailIdOrMobileNumber == undefined || emailIdOrMobileNumber == null) {
3
 
11
			
-
 
12
				alert("Input field emailIdOrMobileNumber can't be empty")
-
 
13
				return;
-
 
14
			}
-
 
15
		if (password == "" || password == null || password == undefined) {
4
$(document).ajaxComplete(
16
			alert("password can't be empty")
5
	function(){
17
			return;
6
		}
18
		}
-
 
19
		submitUser(null, emailIdOrMobileNumber, password)
-
 
20
	});
-
 
21
	$(".forgetPassword").live('click', function() {
-
 
22
		$("#auth").toggle();
-
 
23
		$('#forget-password').toggle();
-
 
24
	});
-
 
25
	$("#recover-password").live('click', function() {
-
 
26
		var email=$("#email").val();
-
 
27
		console.log(email);
-
 
28
		if(email==""|email==null||email==undefined)
-
 
29
			{
-
 
30
				alert("Input field email can't be empty");
-
 
31
				return;
-
 
32
			}
-
 
33
		forgetPassword(email);
-
 
34
	});
-
 
35
});
-
 
36
$(document).ajaxComplete(function() {
7
);
37
});
8
var startApp = function() {
38
var startApp = function() {
9
  gapi.load('auth2', function(){
39
	gapi.load('auth2', function() {
10
    // Retrieve the singleton for the GoogleAuth library and set up the client.
40
		// Retrieve the singleton for the GoogleAuth library and set up the
-
 
41
		// client.
11
    auth2 = gapi.auth2.init({
42
		auth2 = gapi.auth2.init({
12
      client_id: googleApiKey,
43
			client_id : googleApiKey,
13
      cookiepolicy: 'single_host_origin',
44
			cookiepolicy : 'single_host_origin',
14
      // Request scopes in addition to 'profile' and 'email'
45
		// Request scopes in addition to 'profile' and 'email'
15
      //scope: 'additional_scope'
46
		// scope: 'additional_scope'
16
    });
47
		});
17
    attachSignin(document.getElementById('customBtn'));
48
		attachSignin(document.getElementById('customBtn'));
18
  });
49
	});
19
};
50
};
20
 
51
 
21
function attachSignin(element) {
52
function attachSignin(element) {
22
    console.log(element.id);
53
	console.log(element.id);
23
    auth2.attachClickHandler(element, {},
54
	auth2.attachClickHandler(element, {}, function(googleUser) {
24
        function(googleUser) {
-
 
25
    		googleProfile = googleUser.getBasicProfile();
55
		googleProfile = googleUser.getBasicProfile();
26
        	console.log(googleProfile.getImageUrl());
56
		console.log(googleProfile.getImageUrl());
27
        	submitUser(googleUser);
57
		submitUser(googleUser, null,null);
28
        }, function(error) {
58
	}, function(error) {
29
          console.log(JSON.stringify(error, undefined, 2));
59
		console.log(JSON.stringify(error, undefined, 2));
30
        });
60
	});
31
}
61
}
32
 
62
 
-
 
63
function submitUser(googleUser, emailIdOrMobileNumber, password) {
-
 
64
 
33
function submitUser(googleUser){
65
	if (googleUser) {
34
	var params = {
66
		var params = {
35
		"token" : googleUser.getAuthResponse().id_token
67
			"token" : googleUser.getAuthResponse().id_token,
-
 
68
			"emailIdOrMobileNumber" : "",
-
 
69
			"password" : ""
-
 
70
		};
-
 
71
	} else {
-
 
72
		var params = {
-
 
73
			"token":"",
-
 
74
			"emailIdOrMobileNumber" : emailIdOrMobileNumber,
-
 
75
			"password" : password
36
	};
76
		};
-
 
77
	}
37
	//var response = doPostAjaxRequestWithParams(context+"/login", params);
78
	// var response = doPostAjaxRequestWithParams(context+"/login", params);
38
	doAjaxRequestWithParamsHandler(context+"/login", "POST", params, function(response){
79
	doAjaxRequestWithParamsHandler(context + "/login", "POST", params,
-
 
80
			function(response) {
39
		response = JSON.parse(response);
81
				response = JSON.parse(response);
40
		if(response.status){
82
				if (response.status) {
-
 
83
					if(response.name)
-
 
84
						{
-
 
85
						partnerName=response.name;
-
 
86
						}
41
			addProfileInLocalDb();
87
					addProfileInLocalDb();
42
			window.location.href= response.redirectUrl;
88
					window.location.href = response.redirectUrl;
43
		}else{
89
				} else {
44
			alert("Retailer not found, Please login");
90
					alert("Retailer not found, Please login");
-
 
91
				}
-
 
92
			});
-
 
93
 
-
 
94
}
-
 
95
function forgetPassword(emailId)
-
 
96
{
-
 
97
	var params={
-
 
98
			"emailId":emailId
-
 
99
	}
-
 
100
	doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params,
-
 
101
			function(response) {
-
 
102
		if(response=="true")
-
 
103
			{
-
 
104
			$("#login-container").css('display', 'none');
-
 
105
			$('#forget-password').css('display', 'inline-block');
-
 
106
			$("#reset-password").css('display', 'none');
-
 
107
			$('#send-password').css('display', 'inline-block');
45
		}
108
			}
46
	});
109
	});
47
	
-
 
48
}
110
}
49
 
111
 
50
function addProfileInLocalDb(){
-
 
51
	var profile = {'image_url':googleProfile.getImageUrl(),'name':googleProfile.getName()};
-
 
52
	localStorage.setItem("profile",JSON.stringify(profile));
-
 
53
}
-
 
54
112
function addProfileInLocalDb() {
-
 
113
	if(googleProfile){
-
 
114
	var profile = {
-
 
115
		'image_url' : googleProfile.getImageUrl(),
-
 
116
		'name' : googleProfile.getName()
-
 
117
	};
-
 
118
	console.log(googleProfile.getImageUrl);
-
 
119
	console.log(googleProfile.getName());
-
 
120
	localStorage.setItem("profile", JSON.stringify(profile));
-
 
121
}
-
 
122
	else
-
 
123
		{
-
 
124
		var profile = {
-
 
125
				'image_url' : "",
-
 
126
				'name' : partnerName
-
 
127
			};
-
 
128
			console.log(partnerName);
-
 
129
			//console.log(googleProfile.getName());
-
 
130
			localStorage.setItem("profile", JSON.stringify(profile));
-
 
131
		}
-
 
132
	}
-
 
133
55
134