Subversion Repositories SmartDukaan

Rev

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