Subversion Repositories SmartDukaan

Rev

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