Subversion Repositories SmartDukaan

Rev

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