function hi(name) { alert('Hi ' + name) } function getUserData() { let userData = null var is_logged_in = "false" if (is_logged_in == "true" ) { userData = { ContactID : "", FirstName : "", LastName : "", JobTitle : "", Company : "", Email : "", current_ip_address : "", } } return userData; } function gate_this_page() { relogin() } function relogin() { //TO TEST //https://localhost/jslib/main_test.html //https://localhost/tdf/earlyaccess/Hub.aspx //alert('relogin called'); var userData = getUserData() // see if already logged in successfully if ( userData != null ) { // if good then no need to do anything console.log("we have user data so we are good - returning back"); return; } var ck_fallback_cookie = getCookie("fallback_cookie"); // see if fallback cookie exist console.log(ck_fallback_cookie); if ( ! ( ck_fallback_cookie == null || ck_fallback_cookie == "" ) ) // if yes then try to relogin automatically otherwise even relogin will redirect to manual login { // so both IF and ELSE block are same for now console.log("we have fallback cookie, need to redirect to relogin.aspx") location.href = "/tdf/account/relogin.aspx" // need to send url here or may be get it from referrer } else { // for now the relogin takes care of both auto-login as well as manual login so this block is same as IF block console.log("we DO NOT have any cookie, need to redirect to relogin.aspx or manual login") location.href = "/tdf/account/relogin.aspx" // need to send url here or may be get it from referrer } } function silent_login_if_possible() { //TO TEST //https://localhost/jslib/main_test.html //https://localhost/tdf/earlyaccess/Hub.aspx //alert('silent_login_if_possible called'); var userData = getUserData() // see if already logged in successfully if ( userData != null ) { // if good then no need to do anything console.log("we have user data so we are good - returning back"); return; } var ck_fallback_cookie = getCookie("fallback_cookie"); // see if fallback cookie exist console.log(ck_fallback_cookie); if ( ! ( ck_fallback_cookie == null || ck_fallback_cookie == "" ) ) // if yes then try to relogin automatically otherwise even relogin will redirect to manual login { // so both IF and ELSE block are same for now console.log("we have fallback cookie, need to redirect to relogin.aspx") location.href = "/tdf/account/relogin.aspx" // need to send url here or may be get it from referrer } } // ************ UTIL FUNCS ***************** function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); let expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(';'); for(let i = 0; i