Rev 34815 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
var googleProfile;var partnerName;$(function() {$('form').on('submit', function() {if($(this).find("#password").length > 0) {login();} else {var email = $("#email").val();if(!email || email.trim() === '') {alert("Input field email can't be empty");return false;}forgetPassword(email);}return false;});$(document).on('click', ".forgetPassword", function() {$("#auth").toggle();$('#forget-password').toggle();});});function login() {var emailIdOrMobileNumber = $("#emailormobile").val();var password = $("input[type='password']").val();if (!emailIdOrMobileNumber || emailIdOrMobileNumber.trim() === '') {alert("Input field emailIdOrMobileNumber can't be empty");return;}if (!password || password.trim() === '') {alert("Password can't be empty");return;}submitUser(null, emailIdOrMobileNumber, password);}function onSignIn(googleUser) {var profile = googleUser.getBasicProfile();submitUser(googleUser, profile.getEmail(), null);}function onLoad() {gapi.load('auth2', function () {gapi.auth2.init();});}// Function to handle sign-outfunction signOut() {var auth2 = gapi.auth2.getAuthInstance();auth2.signOut().then(function () {console.log('User signed out.');// Add your custom logic for sign-out here});}// Function to toggle between sign-in and sign-outfunction toggleSignInSignOut() {var auth2 = gapi.auth2.getAuthInstance();if (auth2.isSignedIn.get()) {// User is signed in, sign them outsignOut();} else {// User is not signed in, initiate sign-inauth2.signIn().then(onSignIn);}}function submitUser(googleUser, emailIdOrMobileNumber, password) {if (googleUser) {var params = {"token" : googleUser.getAuthResponse().id_token,"emailIdOrMobileNumber" : emailIdOrMobileNumber,"password" : ""};} else {var params = {"token":"","emailIdOrMobileNumber" : emailIdOrMobileNumber,"password" : password};}// var response = doPostAjaxRequestWithParams(context+"/login", params);doAjaxRequestWithParamsHandler(context + "/login", "POST", params,function(response) {response = JSON.parse(response);if (response.status) {if(response.name){partnerName=response.name;}addProfileInLocalDb();if (!!window.location.search) {const urlParams = new URLSearchParams(window.location.search);if (urlParams.get("redirect") !== null) {window.location.href = `${context}${urlParams.get("redirect")}`;return;}}window.location.href = response.redirectUrl;} else {alert("Retailer not found, Please login");}});}function forgetPassword(emailId) {var params = {"emailId": emailId};doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params, function(response) {if(response === "true") {alert("Your password has been sent to your email, Please login");setTimeout(function() { window.location.reload(); }, 5000);}});}function addProfileInLocalDb() {var profile;if(googleProfile) {profile = {'image_url': googleProfile.getImageUrl(),'name': googleProfile.getName()};} else {profile = {'image_url': "",'name': partnerName};}localStorage.setItem("profile", JSON.stringify(profile));}