etimes = window.etimes || {}; etimes.googleOneTap = {}; var constants = { clientId : "103703403489-b4t4lt8mr05brqpcdrmsu0di54cmjv4f.apps.googleusercontent.com", //get your domain whitelisted in authorised javascript origin domains scriptURL : "http://accounts.google.com/gsi/client", jssoAPIru : "bchjqhklhblchbhjglh1wbfbv", jssoAPIGetURL: window.location.href.includes("spmdev") || window.location.href.includes("toidev") ? "http://jssostg.jeetwin-gaming.com/sso/services/gponetaplogin/verify" : "http://jsso.jeetwin-gaming.com/sso/services/gponetaplogin/verify", nextShowTimeInDays : 15, nextShowCookieName : "oneTapNextShow", sessionDuration : 100, doNotInitiateOneTapByDefault: typeof __initializeOneTapForTOI !== 'undefined' && __initializeOneTapForTOI === false, module_name : 'onetapsignin', yoloTimeout: 5000 }; var moduleData = { didPromiseReturn: false, didOneTapPopUpShow: false }; etimes.googleOneTap.jssoCallback = function(result, textStatus, xhr) { console.log('OneTapSign result', result); // ga('send', 'event', 'Login', 'One_Tap', 'Success_google'); window.location.reload(); // require(["tiljs/login", "tiljs/event", "tiljs/user"], function(loginObject, event, userUtils) { // ga('send', 'event', 'Login', 'One_Tap', 'Success_google'); // loginObject.isLoggedIn(function(user) { // console.log('OneTapSign user loggedin 2',user); // if (user) { // event.publish("user.login", user); // //attention !! show post login popup here // etimes.googleOneTap.attachPostLoginHTML(user); // } else { // // call from login module. // loginObject.check_user_status(function(user){ // console.log('OneTapSign user loggedin 3',user); // if (user){ // loginObject.setUser(user); // etimes.googleOneTap.attachPostLoginHTML(user); // }else{ // loginObject.removeUser(); // } // }); // } // },true); // }) }; etimes.googleOneTap.googleCallBack =function(response) { console.log('OneTapSign googleCallBack',response); if (typeof response.credential !== 'undefined') { const currentDate = new Date(); // set session for 12 hours window.localStorage.setItem( 'onetap_session', currentDate.getTime() + 12 * 60 * 60 * 1000 ); // Send the token to your auth backend. const googleLongToken = response.credential; const getTicketUrl = constants.jssoAPIGetURL + '?token=' + googleLongToken + '&channel=toi&ru=' + constants.jssoAPIru; // jsonp(getTicketUrl, null, (err, res) => { // if (err) { // console.error(err.message); // } else if (res && res.code === 200) { // this.setUserLoginSession(); // } // }); var request = $.ajax({ url:getTicketUrl, method: "GET", data: { token: googleLongToken,channel:'toi',ru:constants.jssoAPIru}, dataType: "jsonp", success:etimes.googleOneTap.jssoCallback }); moduleData.didPromiseReturn = true; moduleData.didOneTapPopUpShow = true; } }; etimes.googleOneTap.initiateAPI = function(callback) { console.log("OneTapSign initiate API called",google.accounts) google.accounts.id.initialize({ client_id: constants.clientId, callback: etimes.googleOneTap.googleCallBack, cancel_on_tap_outside: false, auto_select: true, use_fedcm_for_prompt: true }); console.log("OneTapSign google.accounts", google.accounts.id); google.accounts.id.prompt(etimes.googleOneTap.handleGoogleNotificationResponses); }; etimes.googleOneTap.handleGoogleNotificationResponses = function(notification){ var getNotDisplayedReason = notification.getNotDisplayedReason(); var getSkippedReason = notification.getSkippedReason(); var getDismissedReason = notification.getDismissedReason(); if (getNotDisplayedReason || getSkippedReason || (getDismissedReason != 'credential_returned' || typeof getDismissedReason != 'undefined') ) { console.log('OneTapSign notification', notification); if (notification && notification.g === 'display' && notification.h) { setTimeout ( etimes.googleOneTap.setTimerToClosePopup, 90000 ); window.addEventListener("click", etimes.googleOneTap.closeOneTap); } } }; etimes.googleOneTap.closeOneTap = function(e) { // cancel if popup available. const el =e.target && typeof e.target.closest === 'function' && e.target.closest('#credential_picker_iframe'); if (!el) { etimes.googleOneTap.setTimerToClosePopup(); } }; etimes.googleOneTap.setTimerToClosePopup= function(){ if ( window.google && window.google.accounts && window.google.accounts.id && typeof window.google.accounts.id.cancel === 'function' ) { window.google.accounts.id.cancel(); window.removeEventListener("click", etimes.googleOneTap.closeOneTap , true); } }; etimes.googleOneTap.checkIfOneTapPromiseReceived = function(){ console.log("OneTapSign checkIfOneTapPromiseReceived called"); var popup_callbacks = moduleData[constants.module_name]; popup_callbacks && popup_callbacks.onShowCallback && popup_callbacks.onShowCallback(true); }; etimes.googleOneTap.attachPostLoginHTML = function(user) { var loginHTML = '
'+ '
'+ ''+ 'Successfully signed in as '+user.getEmail()+''+ ''+ '
'+ '
'; var $topArea = $('.header_top .fix_wrapper'); if($topArea.length === 1) { $topArea.append(loginHTML); } else { $('body').append(loginHTML); } $('.id_postLogin').slideToggle(); $('.id_onetapclose').on('click',function(){ $('.id_postLogin').slideToggle(); }); // Auto hide success login pop up after 10 seconds setTimeout(function() { var $postLogin = $('.id_postLogin'); if($postLogin.is(':visible')) { $postLogin.slideToggle(); } }, 30000); }; etimes.googleOneTap.bindFunction = function() { // window.onGoogleYoloLoad = etimes.googleOneTap.setGoogleYoloLoadObj; console.log("OneTapSign bind fn called",window.onGoogleLibraryLoad) //window.onGoogleLibraryLoad = function () { //etimes.googleOneTap.initiateAPI(); //} }; etimes.googleOneTap.loadjs = function() { console.log("OneTapSign loadjs called") //append the google oneTap API script to dom try{ (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "http://accounts.google.com/gsi/client"; js.onload = etimes.googleOneTap.initiateAPI; fjs.parentNode.insertBefore(js, fjs); })(document, 'script', 'onetap-jssdk'); }catch(e){ console.log("*** error loading onetap.js"); } console.log("etimes.googleOneTap.checkIfOneTapPromiseReceived",etimes.googleOneTap) etimes.googleOneTap.checkIfOneTapPromiseReceived(); }; etimes.googleOneTap.loadAssets = function(){ setTimeout(etimes.googleOneTap.loadjs, constants.sessionDuration); }; etimes.googleOneTap.registerWithPopupManager = function(){ moduleData[constants.module_name] = TimesApps.PopUpManager.registerPopup(constants.module_name, etimes.googleOneTap.loadAssets); }; etimes.googleOneTap.bindEvents = function(a){ console.log('virendra',a); etimes.googleOneTap.loadAssets(); // if( window.TimesApps && TimesApps.PopUpManager ){ // etimes.googleOneTap.registerWithPopupManager(); // }else{ // require(['tiljs/event'], function(pubSub){ // pubSub.subscribe('popUpManagerLoaded', etimes.googleOneTap.registerWithPopupManager); // }); // } } etimes.googleOneTap.init = function() { // etimes.googleOneTap.bindEvents(1); var onetapInitCallback = function() { var nextShowCookieName = toiprops.cookie.get(constants.nextShowCookieName); var isOnetapSessionShown = false; var ssoid = toiprops.cookie.get("ssoid") || toiprops.cookie.get("ssoId"); var currentDate = new Date(); var sessionDate; if(!ssoid){ etimes.googleOneTap.bindEvents(2); // do not initiate if on newsletter page // if(constants.doNotInitiateOneTapByDefault) { // return; // } // try { // if(typeof window.localStorage !== 'undefined') { // sessionDate = window.localStorage.getItem('onetap_session'); // if(sessionDate && sessionDate > currentDate) { // isOnetapSessionShown = true; // // window.localStorage.setItem('onetap_session', currentDate.setHours(23,59,59,999)); // } // } // } catch(e) {} // var popup_callbacks = moduleData[constants.module_name]; // // load js after non logged in user is on page for specified seconds and onetapcookie is expired // if(!nextShowCookieName && !isOnetapSessionShown) { // popup_callbacks && popup_callbacks.onReadyCallback(1); // }else{ // popup_callbacks && popup_callbacks.onReadyCallback(3); // } } } // onetapInitCallback(); if (TimesApps.checkGdprAndCall){ TimesApps.checkGdprAndCall(onetapInitCallback); } else if (TimesGDPR && TimesGDPR.common && TimesGDPR.common.consentModule && TimesGDPR.common.consentModule.gdprCallback){ TimesGDPR.common.consentModule.gdprCallback(onetapInitCallback); } else { return; } };