Subversion Repositories SmartDukaan

Rev

Rev 32390 | Rev 33085 | 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
 
33061 ranu 71
function onSignIn(googleUser) {
72
	var profile = googleUser.getBasicProfile();
73
	submitUser(googleUser, profile.getEmail(), null);
74
}
75
 
24383 amit.gupta 76
function submitUser(googleUser, emailIdOrMobileNumber, password) {
77
 
78
	if (googleUser) {
79
		var params = {
80
			"token" : googleUser.getAuthResponse().id_token,
25245 amit.gupta 81
			"emailIdOrMobileNumber" : emailIdOrMobileNumber,
24383 amit.gupta 82
			"password" : ""
83
		};
84
	} else {
85
		var params = {
86
			"token":"",
87
			"emailIdOrMobileNumber" : emailIdOrMobileNumber,
88
			"password" : password
89
		};
90
	}
91
	// var response = doPostAjaxRequestWithParams(context+"/login", params);
92
	doAjaxRequestWithParamsHandler(context + "/login", "POST", params,
93
			function(response) {
94
				response = JSON.parse(response);
95
				if (response.status) {
96
					if(response.name)
97
						{
98
						partnerName=response.name;
99
						}
100
					addProfileInLocalDb();
32390 amit.gupta 101
					if (!!window.location.search) {
102
						const urlParams = new URLSearchParams(window.location.search);
103
						if (urlParams.get("redirect") !== null) {
104
							window.location.href = `${context}${urlParams.get("redirect")}`;
105
							return;
106
						}
107
					}
24383 amit.gupta 108
					window.location.href = response.redirectUrl;
109
				} else {
110
					alert("Retailer not found, Please login");
111
				}
112
			});
113
 
114
}
115
function forgetPassword(emailId)
116
{
117
	var params={
118
			"emailId":emailId
119
	}
120
	doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params,
121
			function(response) {
122
		if(response=="true")
123
			{
124
			$("#login-container").css('display', 'none');
125
			$('#forget-password').css('display', 'inline-block');
126
			$("#reset-password").css('display', 'none');
127
			$('#send-password').css('display', 'inline-block');
128
			}
23343 ashik.ali 129
	});
130
}
131
 
24383 amit.gupta 132
function addProfileInLocalDb() {
133
	if(googleProfile){
134
	var profile = {
135
		'image_url' : googleProfile.getImageUrl(),
136
		'name' : googleProfile.getName()
137
	};
138
	console.log(googleProfile.getImageUrl);
139
	console.log(googleProfile.getName());
140
	localStorage.setItem("profile", JSON.stringify(profile));
141
}
142
	else
143
		{
144
		var profile = {
145
				'image_url' : "",
146
				'name' : partnerName
147
			};
148
			console.log(partnerName);
149
			//console.log(googleProfile.getName());
150
			localStorage.setItem("profile", JSON.stringify(profile));
151
		}
152
	}