Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
23343 ashik.ali 1
var googleProfile;
24383 amit.gupta 2
var partnerName;
3
$(function() {
23343 ashik.ali 4
 
24383 amit.gupta 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) {
11
 
12
				alert("Input field emailIdOrMobileNumber can't be empty")
13
				return;
14
			}
15
		if (password == "" || password == null || password == undefined) {
16
			alert("password can't be empty")
17
			return;
23343 ashik.ali 18
		}
24383 amit.gupta 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() {
37
});
23343 ashik.ali 38
var startApp = function() {
24383 amit.gupta 39
	gapi.load('auth2', function() {
40
		// Retrieve the singleton for the GoogleAuth library and set up the
41
		// client.
42
		auth2 = gapi.auth2.init({
43
			client_id : googleApiKey,
44
			cookiepolicy : 'single_host_origin',
45
		// Request scopes in addition to 'profile' and 'email'
46
		// scope: 'additional_scope'
47
		});
48
		attachSignin(document.getElementById('customBtn'));
49
	});
23343 ashik.ali 50
};
51
 
52
function attachSignin(element) {
24383 amit.gupta 53
	console.log(element.id);
54
	auth2.attachClickHandler(element, {}, function(googleUser) {
55
		googleProfile = googleUser.getBasicProfile();
56
		console.log(googleProfile.getImageUrl());
57
		submitUser(googleUser, null,null);
58
	}, function(error) {
59
		console.log(JSON.stringify(error, undefined, 2));
60
	});
23343 ashik.ali 61
}
62
 
24383 amit.gupta 63
function submitUser(googleUser, emailIdOrMobileNumber, password) {
64
 
65
	if (googleUser) {
66
		var params = {
67
			"token" : googleUser.getAuthResponse().id_token,
68
			"emailIdOrMobileNumber" : "",
69
			"password" : ""
70
		};
71
	} else {
72
		var params = {
73
			"token":"",
74
			"emailIdOrMobileNumber" : emailIdOrMobileNumber,
75
			"password" : password
76
		};
77
	}
78
	// var response = doPostAjaxRequestWithParams(context+"/login", params);
79
	doAjaxRequestWithParamsHandler(context + "/login", "POST", params,
80
			function(response) {
81
				response = JSON.parse(response);
82
				if (response.status) {
83
					if(response.name)
84
						{
85
						partnerName=response.name;
86
						}
87
					addProfileInLocalDb();
88
					window.location.href = response.redirectUrl;
89
				} else {
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');
108
			}
23343 ashik.ali 109
	});
110
}
111
 
24383 amit.gupta 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
	}