Subversion Repositories SmartDukaan

Rev

Rev 35458 | 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 {
35459 amit 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
				}
25375 amit.gupta 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
});
35459 amit 27
$(document).ajaxComplete(function() {
28
});
23343 ashik.ali 29
 
25085 amit.gupta 30
function login() {
35459 amit 31
	console.log("Login DashBoard");
25085 amit.gupta 32
	var emailIdOrMobileNumber = $("#emailormobile").val();
35459 amit 33
	console.log(emailormobile);
25085 amit.gupta 34
	var password = $("input[type='password']").val();
35459 amit 35
	if (emailIdOrMobileNumber == "" || emailIdOrMobileNumber == undefined || emailIdOrMobileNumber == null) {
36
 
37
			alert("Input field emailIdOrMobileNumber can't be empty")
38
			return;
39
		}
40
	if (password == "" || password == null || password == undefined) {
41
		alert("password can't be empty")
25085 amit.gupta 42
		return;
43
	}
35459 amit 44
	submitUser(null, emailIdOrMobileNumber, password)
25085 amit.gupta 45
}
46
 
33061 ranu 47
function onSignIn(googleUser) {
48
	var profile = googleUser.getBasicProfile();
49
	submitUser(googleUser, profile.getEmail(), null);
50
}
51
 
33085 ranu 52
function onLoad() {
53
	gapi.load('auth2', function () {
54
		gapi.auth2.init();
55
	});
56
}
57
 
58
// Function to handle sign-out
59
function signOut() {
60
	var auth2 = gapi.auth2.getAuthInstance();
61
	auth2.signOut().then(function () {
62
		console.log('User signed out.');
63
		// Add your custom logic for sign-out here
64
	});
65
}
66
 
67
// Function to toggle between sign-in and sign-out
68
function toggleSignInSignOut() {
69
	var auth2 = gapi.auth2.getAuthInstance();
70
	if (auth2.isSignedIn.get()) {
71
		// User is signed in, sign them out
72
		signOut();
73
	} else {
74
		// User is not signed in, initiate sign-in
75
		auth2.signIn().then(onSignIn);
76
	}
77
}
78
 
24383 amit.gupta 79
function submitUser(googleUser, emailIdOrMobileNumber, password) {
80
 
81
	if (googleUser) {
82
		var params = {
83
			"token" : googleUser.getAuthResponse().id_token,
25245 amit.gupta 84
			"emailIdOrMobileNumber" : emailIdOrMobileNumber,
24383 amit.gupta 85
			"password" : ""
86
		};
87
	} else {
88
		var params = {
89
			"token":"",
90
			"emailIdOrMobileNumber" : emailIdOrMobileNumber,
91
			"password" : password
92
		};
93
	}
94
	// var response = doPostAjaxRequestWithParams(context+"/login", params);
95
	doAjaxRequestWithParamsHandler(context + "/login", "POST", params,
96
			function(response) {
97
				response = JSON.parse(response);
98
				if (response.status) {
99
					if(response.name)
100
						{
101
						partnerName=response.name;
102
						}
103
					addProfileInLocalDb();
32390 amit.gupta 104
					if (!!window.location.search) {
105
						const urlParams = new URLSearchParams(window.location.search);
106
						if (urlParams.get("redirect") !== null) {
107
							window.location.href = `${context}${urlParams.get("redirect")}`;
108
							return;
109
						}
110
					}
24383 amit.gupta 111
					window.location.href = response.redirectUrl;
112
				} else {
113
					alert("Retailer not found, Please login");
114
				}
115
			});
116
 
117
}
35459 amit 118
function forgetPassword(emailId)
119
{
120
	var params={"emailId":emailId };
34815 vikas 121
	doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params, function(response) {
35459 amit 122
		console.log(response, typeof response);
123
		if(response=="true") {
34815 vikas 124
			alert("Your password has been sent to your email, Please login");
35459 amit 125
			setTimeout(function(){ window.location.reload(); }, 5000);
34815 vikas 126
		}
23343 ashik.ali 127
	});
128
}
129
 
24383 amit.gupta 130
function addProfileInLocalDb() {
35459 amit 131
	if(googleProfile){
132
	var profile = {
133
		'image_url' : googleProfile.getImageUrl(),
134
		'name' : googleProfile.getName()
135
	};
136
	console.log(googleProfile.getImageUrl);
137
	console.log(googleProfile.getName());
24383 amit.gupta 138
	localStorage.setItem("profile", JSON.stringify(profile));
35459 amit 139
}
140
	else
141
		{
142
		var profile = {
143
				'image_url' : "",
144
				'name' : partnerName
145
			};
146
			console.log(partnerName);
147
			//console.log(googleProfile.getName());
148
			localStorage.setItem("profile", JSON.stringify(profile));
149
		}
150
	}