1var CANDEE_SERVER_AUTH_BRIDGE = { 2 getSameSiteValue: function(){ 3 return window.location.protocol == 'https:' ? 'None' : 'Lax'; 4 }, 5 shouldUseSecureCookie: function(){ 6 return window.location.protocol == 'https:'; 7 }, 8 getCookieValue: function(cookieName){ 9 var cookieValues = this.getCookieValues(cookieName); 10 return cookieValues.length ? cookieValues[0] : ''; 11 }, 12 getCookieValues: function(cookieName){ 13 var escapedName = ''; 14 var regex = null; 15 var matches = []; 16 var match = null; 17 18 if (!cookieName){ 19 return matches; 20 } 21 22 escapedName = cookieName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); 23 regex = new RegExp('(?:^|; )' + escapedName + '=([^;]*)', 'g'); 24 25 while ((match = regex.exec(document.cookie)) !== null){ 26 if (match[1]){ 27 matches.push(decodeURIComponent(match[1])); 28 } 29 } 30 31 return matches.filter(function(value, index){ 32 return value && matches.indexOf(value) === index; 33 }); 34 }, 35 getCookieDomains: function(){ 36 var host = window.location.hostname ? window.location.hostname.toLowerCase() : ''; 37 var domains = ['']; 38 var pushUnique = function(value){ 39 if (!value){ 40 return; 41 } 42 43 if (domains.indexOf(value) === -1){ 44 domains.push(value); 45 } 46 }; 47 48 if (!host){ 49 return domains; 50 } 51 52 pushUnique(host); 53 54 if (/^\d{1,3}(\.\d{1,3}){3}$/.test(host) || host === 'localhost'){ 55 return domains; 56 } 57 58 pushUnique('.' + host); 59 60 if (host.indexOf('www.') === 0){ 61 pushUnique(host.substring(4)); 62 pushUnique('.' + host.substring(4)); 63 } 64 65 return domains; 66 }, 67 getCookiePaths: function(){ 68 var pathname = window.location.pathname ? window.location.pathname : '/'; 69 var parts = pathname.split('/').filter(Boolean); 70 var paths = ['/']; 71 var currentPath = ''; 72 var pushUnique = function(value){ 73 if (paths.indexOf(value) === -1){ 74 paths.push(value); 75 } 76 }; 77 78 parts.forEach(function(part){ 79 currentPath += '/' + part; 80 pushUnique(currentPath); 81 pushUnique(currentPath + '/'); 82 }); 83 84 return paths; 85 }, 86 getAppId: function(){ 87 return CANDEE_SERVER_AUTH_BRIDGE_CONFIG.app_id ? String(CANDEE_SERVER_AUTH_BRIDGE_CONFIG.app_id) : ''; 88 }, 89 getIframeAuthParamName: function(){ 90 return CANDEE_SERVER_AUTH_BRIDGE_CONFIG.iframe_auth_param ? String(CANDEE_SERVER_AUTH_BRIDGE_CONFIG.iframe_auth_param) : 'candee_iframe_auth'; 91 }, 92 getIframeAuthStorageKey: function(){ 93 var appId = this.getAppId(); 94 return appId ? 'candee_iframe_auth_' + appId : 'candee_iframe_auth'; 95 }, 96 isIframeContext: function(){ 97 try { 98 return window.self != window.top; 99 } catch (err) { 100 return true; 101 } 102 }, 103 cleanIframeAuthToken: function(value){ 104 value = typeof value === 'string' ? value : ''; 105 return value.replace(/[^A-Za-z0-9]/g, ''); 106 }, 107 getUrlParam: function(url, key){ 108 var escapedKey = key ? key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') : ''; 109 var regex = null; 110 var match = null; 111 112 if (!escapedKey || !url){ 113 return ''; 114 } 115 116 regex = new RegExp('[?&]' + escapedKey + '=([^&#]*)'); 117 match = regex.exec(url); 118 119 return match && match[1] ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : ''; 120 }, 121 setUrlParam: function(url, key, value){ 122 var hash = ''; 123 var hashIndex = -1; 124 var prefix = encodeURIComponent(key) + '='; 125 var urlparts = null; 126 var base = ''; 127 var pars = []; 128 var nextPars = []; 129 var found = false; 130 var i = 0; 131 132 if (!url || !key){ 133 return url; 134 } 135 136 hashIndex = url.indexOf('#'); 137 if (hashIndex > -1){ 138 hash = url.substring(hashIndex); 139 url = url.substring(0, hashIndex); 140 } 141 142 urlparts = url.split('?'); 143 base = urlparts[0]; 144 pars = urlparts.length > 1 && urlparts[1] ? urlparts[1].split(/[&;]/g) : []; 145 146 for (i = 0; i < pars.length; i++){ 147 if (!pars[i]){ 148 continue; 149 } 150 151 if (pars[i].lastIndexOf(prefix, 0) === 0){ 152 nextPars.push(prefix + encodeURIComponent(value)); 153 found = true; 154 } else { 155 nextPars.push(pars[i]); 156 } 157 } 158 159 if (!found){ 160 nextPars.push(prefix + encodeURIComponent(value)); 161 } 162 163 return base + (nextPars.length > 0 ? '?' + nextPars.join('&') : '') + hash; 164 }, 165 readIframeStorageValue: function(key){ 166 var storages = []; 167 var value = ''; 168 var i = 0; 169 170 if (!key){ 171 return ''; 172 } 173 174 if (typeof LOCALSTORAGE !== 'undefined'){ 175 storages.push(LOCALSTORAGE); 176 } 177 178 if (typeof localStorage !== 'undefined'){ 179 storages.push(localStorage); 180 } 181 182 if (typeof sessionStorage !== 'undefined'){ 183 storages.push(sessionStorage); 184 } 185 186 for (i = 0; i < storages.length; i++){ 187 try { 188 if (storages[i] && typeof storages[i].getItem === 'function'){ 189 value = storages[i].getItem(key); 190 if (value !== null && typeof value !== 'undefined' && value !== ''){ 191 return value; 192 } 193 } 194 } catch (err) {} 195 } 196 197 return ''; 198 }, 199 writeIframeStorageValue: function(key, value){ 200 var storages = []; 201 var i = 0; 202 203 if (!key || !value){ 204 return; 205 } 206 207 if (typeof LOCALSTORAGE !== 'undefined'){ 208 storages.push(LOCALSTORAGE); 209 } 210 211 if (typeof localStorage !== 'undefined'){ 212 storages.push(localStorage); 213 } 214 215 if (typeof sessionStorage !== 'undefined'){ 216 storages.push(sessionStorage); 217 } 218 219 for (i = 0; i < storages.length; i++){ 220 try { 221 if (storages[i] && typeof storages[i].setItem === 'function'){ 222 storages[i].setItem(key, value); 223 } 224 } catch (err) {} 225 } 226 }, 227 removeIframeStorageValue: function(key){ 228 var storages = []; 229 var i = 0; 230 231 if (!key){ 232 return; 233 } 234 235 if (typeof LOCALSTORAGE !== 'undefined'){ 236 storages.push(LOCALSTORAGE); 237 } 238 239 if (typeof localStorage !== 'undefined'){ 240 storages.push(localStorage); 241 } 242 243 if (typeof sessionStorage !== 'undefined'){ 244 storages.push(sessionStorage); 245 } 246 247 for (i = 0; i < storages.length; i++){ 248 try { 249 if (storages[i] && typeof storages[i].removeItem === 'function'){ 250 storages[i].removeItem(key); 251 } 252 } catch (err) {} 253 } 254 }, 255 getStoredIframeAuth: function(){ 256 return this.cleanIframeAuthToken(this.readIframeStorageValue(this.getIframeAuthStorageKey())); 257 }, 258 setStoredIframeAuth: function(value){ 259 value = this.cleanIframeAuthToken(value); 260 261 if (!value){ 262 return; 263 } 264 265 this.writeIframeStorageValue(this.getIframeAuthStorageKey(), value); 266 }, 267 clearStoredIframeAuth: function(){ 268 this.removeIframeStorageValue(this.getIframeAuthStorageKey()); 269 }, 270 getIframeAuthValue: function(){ 271 var urlValue = this.cleanIframeAuthToken(this.getUrlParam(window.location.href, this.getIframeAuthParamName())); 272 var storedValue = ''; 273 274 if (urlValue){ 275 this.setStoredIframeAuth(urlValue); 276 return urlValue; 277 } 278
279 storedValue = this.getStoredIframeAuth(); 280 return storedValue ? storedValue : ''; 281 }, 282 getIframeAwareLinkKeys: function(){ 283 return [ 284 'account_link', 285 'orders_link', 286 'profile_link', 287 'login_link', 288 'account_link_fr', 289 'orders_link_fr', 290 'profile_link_fr', 291 'login_link_fr', 292 'account_link_es', 293 'orders_link_es', 294 'profile_link_es', 295 'login_link_es' 296 ]; 297 }, 298 normalizeIframeAwareTarget: function(url){ 299 var link = null; 300 var pathname = ''; 301 302 if (!url || typeof url !== 'string'){ 303 return ''; 304 } 305 306 link = document.createElement('a'); 307 link.href = url; 308 pathname = link.pathname ? link.pathname : url; 309 pathname = pathname.charAt(0) != '/' ? '/' + pathname : pathname; 310 pathname = pathname[pathname.length - 1] == '/' ? pathname : pathname + '/'; 311 312 return pathname.toLowerCase(); 313 }, 314 isIframeAwareTarget: function(url){ 315 var me = this; 316 var normalizedTarget = this.normalizeIframeAwareTarget(url); 317 var linkKeys = this.getIframeAwareLinkKeys(); 318 319 if (!normalizedTarget || typeof candee_js_variables !== 'object'){ 320 return false; 321 } 322 323 return linkKeys.some(function(key){ 324 return me.normalizeIframeAwareTarget(candee_js_variables[key]) === normalizedTarget; 325 }); 326 }, 327 shouldUseIframeAuth: function(){ 328 return this.isIframeContext() 329 || this.getUrlParam(window.location.href, 'candee_iframe') === '1' 330 || this.getIframeAuthValue() !== ''; 331 }, 332 appendIframeAuthToUrl: function(url){ 333 var iframeAuthValue = ''; 334 335 if (!url || !this.shouldUseIframeAuth() || !this.isIframeAwareTarget(url)){ 336 return url; 337 } 338 339 url = this.setUrlParam(url, 'candee_iframe', '1'); 340 iframeAuthValue = this.getIframeAuthValue(); 341 342 if (iframeAuthValue){ 343 url = this.setUrlParam(url, this.getIframeAuthParamName(), iframeAuthValue); 344 } 345 346 return url; 347 }, 348 updateIframeAwareLinks: function(){ 349 var me = this; 350 var linkKeys = null; 351 352 if (typeof candee_js_variables !== 'object' || !this.shouldUseIframeAuth()){ 353 return; 354 } 355 356 linkKeys = this.getIframeAwareLinkKeys(); 357 358 linkKeys.forEach(function(key){ 359 if (!candee_js_variables[key]){ 360 return; 361 } 362 363 candee_js_variables[key] = me.appendIframeAuthToUrl(candee_js_variables[key]); 364 }); 365 }, 366 updateIframeAwareDocumentLinks: function(){ 367 if (!window.cQuery || !this.shouldUseIframeAuth()){ 368 return; 369 } 370 371 cQuery('a[href]').each(function(){ 372 var currentHref = cQuery(this).attr('href'); 373 var nextHref = CANDEE_SERVER_AUTH_BRIDGE.appendIframeAuthToUrl(currentHref); 374 375 if (nextHref && nextHref !== currentHref){ 376 cQuery(this).attr('href', nextHref); 377 } 378 }); 379 }, 380 setCookie: function(sessionKey, ttl){ 381 var cookieName = CANDEE_SERVER_AUTH_BRIDGE_CONFIG.cookie_name ? CANDEE_SERVER_AUTH_BRIDGE_CONFIG.cookie_name : ''; 382 var cookie = ''; 383 var sameSite = this.getSameSiteValue(); 384 var useSecure = this.shouldUseSecureCookie(); 385 386 if (!cookieName || !sessionKey){ 387 return; 388 } 389 390 ttl = ttl ? parseInt(ttl, 10) : parseInt(CANDEE_SERVER_AUTH_BRIDGE_CONFIG.ttl || 0, 10); 391 cookie = cookieName + '=' + encodeURIComponent(sessionKey) + '; path=/'; 392 393 if (ttl > 0){ 394 cookie += '; max-age=' + ttl; 395 } 396 397 cookie += '; SameSite=' + sameSite; 398 399 if (useSecure){ 400 cookie += '; Secure'; 401 } 402 403 var cookieBase = cookie; 404 this.getCookieDomains().forEach(function(domain){ 405 var finalCookie = cookieBase; 406 if (domain) { 407 finalCookie += '; domain=' + domain; 408 } 409 document.cookie = finalCookie; 410 }); 411 }, 412 clearCookie: function(){ 413 var cookieName = CANDEE_SERVER_AUTH_BRIDGE_CONFIG.cookie_name ? CANDEE_SERVER_AUTH_BRIDGE_CONFIG.cookie_name : ''; 414 var domains = []; 415 var paths = []; 416 417 if (!cookieName){ 418 return; 419 } 420 421 domains = this.getCookieDomains(); 422 paths = this.getCookiePaths();
423 var sameSite = this.getSameSiteValue(); 424 var useSecure = this.shouldUseSecureCookie(); 425 426 domains.forEach(function(domain){ 427 paths.forEach(function(path){ 428 var cookie = cookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=' + path + '; SameSite=' + sameSite; 429 430 if (domain){ 431 cookie += '; domain=' + domain; 432 } 433 434 document.cookie = cookie; 435 436 if (useSecure){ 437 document.cookie = cookie + '; Secure'; 438 } 439 }); 440 }); 441 }, 442 getTraceKey: function(){ 443 return 'candee_server_auth_trace'; 444 }, 445 trace: function(step, payload){ 446 var entry = { 447 at: (new Date()).toISOString(), 448 step: step ? step : '', 449 payload: payload ? payload : {} 450 }; 451 var history = []; 452 453 try { 454 history = LOCALSTORAGE.getItem(this.getTraceKey()); 455 history = history ? JSON.parse(history) : []; 456 457 if (!Array.isArray(history)){ 458 history = []; 459 } 460 461 history.push(entry); 462 history = history.slice(-40); 463 464 LOCALSTORAGE.setItem(this.getTraceKey(), JSON.stringify(history)); 465 } catch(err){} 466 467 // if (window.console && typeof window.console.log == 'function'){ 468 // console.log('[CANDEE AUTH TRACE]', entry); 469 // } 470 }, 471 getUser: function(){ 472 try { 473 var user = LOCALSTORAGE.getItem('tsg_user'); 474 475 if (!user){ 476 return false; 477 } 478 479 user = JSON.parse(user); 480 481 if (!user || !user.email_address || user.email_address == '[email protected]'){ 482 return false; 483 } 484 485 return user; 486 } catch(err){ 487 return false; 488 } 489 }, 490 getSerializableUser: function(user){ 491 var payload = {}; 492 var allowedKeys = [ 493 'id', 494 'email_address', 495 'user_token', 496 'property_id', 497 'first_name', 498 'last_name', 499 'postal_code', 500 'phone', 501 'mobile_phone', 502 'country_code', 503 'city', 504 'state', 505 'address_1', 506 'address_2', 507 'country', 508 'related_logins', 509 'top_prop_id', 510 'settings', 511 'alt_contact_info', 512 'validation_answers' 513 ]; 514 515 user = user ? user : this.getUser(); 516 517 if (!user || typeof user !== 'object'){ 518 return payload; 519 } 520 521 allowedKeys.forEach(function(key){ 522 var value = user[key]; 523 524 if (typeof value === 'undefined' || value === null){ 525 return; 526 } 527 528 if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'){ 529 payload[key] = value; 530 return; 531 } 532 533 try { 534 payload[key] = JSON.stringify(value); 535 } catch (err) {} 536 }); 537 538 return payload; 539 }, 540 ajax: function(action, data){ 541 data = data ? data : {}; 542 data.action = action; 543 data.nonce = ajaxnonce; 544 545 return cQuery.ajax({ 546 url: ajaxurl, 547 type: 'POST', 548 data: data, 549 cache: false 550 }); 551 }, 552 syncLogin: function(user){ 553 user = user ? user : this.getUser(); 554 555 if (!user){ 556 this.trace('syncLogin:missing_user'); 557 return; 558 } 559 560 this.trace('syncLogin:start', { 561 email: user.email_address ? user.email_address : '', 562 property_id: user.property_id ? user.property_id : '', 563 has_user_token: !!(user.user_token) 564 }); 565 566 return this.ajax('candee_server_auth_bridge_login', { 567 is_iframe: this.isIframeContext() ? '1' : '0', 568 candee_iframe: this.shouldUseIframeAuth() ? '1' : '0', 569 iframe_auth: this.getIframeAuthValue(), 570 // Legacy payload only sent 4 fields and caused rehydrated users to be 571 // incomplete after refresh on old Candee templates. 572 // user: { 573 // id: user.id ? user.id : '', 574 // email_address: user.email_address ? user.email_address : '', 575 // user_token: user.user_token ? user.user_token : '', 576 // property_id: user.property_id ? user.property_id : '' 577 // }
578 user: this.getSerializableUser(user) 579 }).done(function(response){ 580 var hasSessionKey = response && response.success && response.data && response.data.session_key; 581 582 CANDEE_SERVER_AUTH_BRIDGE.trace('syncLogin:done', { 583 success: !!hasSessionKey, 584 response_success: !!(response && response.success), 585 session_key_tail: hasSessionKey ? String(response.data.session_key).slice(-8) : '' 586 }); 587 588 if (!response || !response.success || !response.data || !response.data.session_key){ 589 return; 590 } 591 592 if (response.data.iframe_auth){ 593 CANDEE_SERVER_AUTH_BRIDGE.setStoredIframeAuth(response.data.iframe_auth); 594 CANDEE_SERVER_AUTH_BRIDGE.updateIframeAwareLinks(); 595 } 596 597 CANDEE_SERVER_AUTH_BRIDGE.setCookie(response.data.session_key, response.data.ttl); 598 LOCALSTORAGE.setItem('candee_server_auth_last_sync', Date.now().toString()); 599 600 if (typeof candee_js_variables == 'object'){ 601 candee_js_variables.server_auth_authed = true; 602 } 603 }).fail(function(xhr, textStatus, errorThrown){ 604 CANDEE_SERVER_AUTH_BRIDGE.trace('syncLogin:fail', { 605 http_status: xhr && xhr.status ? xhr.status : '', 606 text_status: textStatus ? textStatus : '', 607 error: errorThrown ? errorThrown : '', 608 response_text: xhr && xhr.responseText ? String(xhr.responseText).substring(0, 200) : '' 609 }); 610 }); 611 }, 612 syncLogout: function(){ 613 var cookieName = CANDEE_SERVER_AUTH_BRIDGE_CONFIG.cookie_name ? CANDEE_SERVER_AUTH_BRIDGE_CONFIG.cookie_name : ''; 614 var sessionKeys = this.getCookieValues(cookieName); 615 var sessionKey = sessionKeys.length ? sessionKeys[0] : ''; 616 var iframeAuthValue = this.getIframeAuthValue(); 617 618 LOCALSTORAGE.removeItem('candee_server_auth_last_sync'); 619 // Clearing the browser cookie before the server logout finishes can 620 // race against PHP cleanup on older environments. 621 // this.clearCookie(); 622 623 if (typeof candee_js_variables == 'object'){ 624 candee_js_variables.server_auth_authed = false; 625 } 626 627 return this.ajax('candee_server_auth_bridge_logout', { 628 session_key: sessionKey, 629 session_keys: sessionKeys, 630 iframe_auth: iframeAuthValue, 631 candee_iframe: this.shouldUseIframeAuth() ? '1' : '0' 632 }).always(function(){ 633 CANDEE_SERVER_AUTH_BRIDGE.clearCookie(); 634 CANDEE_SERVER_AUTH_BRIDGE.clearStoredIframeAuth(); 635 }); 636 }, 637 refreshSession: function(){ 638 var user = this.getUser(); 639 640 if (!user){ 641 return; 642 } 643 644 return this.ajax('candee_server_auth_bridge_refresh', { 645 is_iframe: this.isIframeContext() ? '1' : '0', 646 candee_iframe: this.shouldUseIframeAuth() ? '1' : '0', 647 iframe_auth: this.getIframeAuthValue(), 648 // Legacy payload only sent 4 fields and caused refresh rehydration 649 // to lose data expected by older UI modules. 650 // user: { 651 // id: user.id ? user.id : '', 652 // email_address: user.email_address ? user.email_address : '', 653 // user_token: user.user_token ? user.user_token : '', 654 // property_id: user.property_id ? user.property_id : '' 655 // } 656 user: this.getSerializableUser(user) 657 }).done(function(response){ 658 if (!response || !response.success || !response.data || !response.data.session_key){ 659 return; 660 } 661 662 if (response.data.iframe_auth){ 663 CANDEE_SERVER_AUTH_BRIDGE.setStoredIframeAuth(response.data.iframe_auth); 664 CANDEE_SERVER_AUTH_BRIDGE.updateIframeAwareLinks(); 665 } 666 667 CANDEE_SERVER_AUTH_BRIDGE.setCookie(response.data.session_key, response.data.ttl); 668 LOCALSTORAGE.setItem('candee_server_auth_last_sync', Date.now().toString()); 669 670 if (typeof candee_js_variables == 'object'){
671 candee_js_variables.server_auth_authed = true; 672 } 673 }); 674 }, 675 init: function(attempt){ 676 attempt = attempt ? attempt : 0; 677 var cookieName = CANDEE_SERVER_AUTH_BRIDGE_CONFIG.cookie_name ? CANDEE_SERVER_AUTH_BRIDGE_CONFIG.cookie_name : ''; 678 var hasBridgeCookie = !!this.getCookieValue(cookieName); 679 var user = false; 680 681 if (window.self != window.top && LOCALSTORAGE.getItem('candee_storage_loaded') != 'true'){ 682 if (attempt < 20){ 683 window.setTimeout(function(){ 684 CANDEE_SERVER_AUTH_BRIDGE.init(attempt + 1); 685 }, 250); 686 } 687 return; 688 } 689 690 user = this.getUser(); 691 692 if (!hasBridgeCookie && user){ 693 if (this.shouldUseIframeAuth() && this.getIframeAuthValue()){ 694 this.trace('init:cookie_missing_but_iframe_auth_present'); 695 this.updateIframeAwareLinks(); 696 return; 697 } 698 699 // Server has no cookie, but client has user. 700 // This is a logout or expiration from another context. 701 this.trace('init:cookie_missing_but_user_exists_clearing_local_state'); 702 if (window.SHARED && typeof SHARED.clearAuthClientState === 'function'){ 703 SHARED.clearAuthClientState(true); 704 } 705 return; 706 } 707 708 if (!hasBridgeCookie && typeof candee_js_variables == 'object'){ 709 candee_js_variables.server_auth_authed = false; 710 } 711 712 this.updateIframeAwareLinks(); 713 }, 714 installSharedIframeRouting: function(){ 715 var me = this; 716 var originalRouter = null; 717 var originalReload = null; 718 719 if (!window.SHARED || typeof window.SHARED !== 'object' || SHARED._candeeIframeAuthWrapped === true){ 720 return; 721 } 722 723 originalRouter = typeof SHARED.router === 'function' ? SHARED.router : null; 724 originalReload = typeof SHARED.reload === 'function' ? SHARED.reload : null; 725 726 SHARED.router = function(page){ 727 page = me.appendIframeAuthToUrl(page); 728 729 if (originalRouter){ 730 return originalRouter.call(SHARED, page); 731 } 732 733 window.location.href = page; 734 }; 735 736 SHARED.reload = function(){ 737 var nextUrl = me.appendIframeAuthToUrl(window.location.href); 738 739 if (nextUrl && nextUrl !== window.location.href){ 740 window.location.replace(nextUrl); 741 return; 742 } 743 744 if (originalReload){ 745 return originalReload.call(SHARED); 746 } 747 748 window.location.reload(); 749 }; 750 751 SHARED._candeeIframeAuthWrapped = true; 752 }, 753 installSharedLogoutHardening: function(){ 754 if (!window.SHARED || typeof window.SHARED !== 'object'){ 755 return; 756 } 757 758 SHARED.getLogoutStorageKeys = function(){ 759 var appId = (typeof candee_js_variables !== 'undefined' && candee_js_variables.app_id) ? candee_js_variables.app_id : ''; 760 var keys = [ 761 'tsg_user', 762 'candee_session', 763 'tsg_order_token', 764 'candee_server_auth_last_sync', 765 'candee_loggedin', 766 'tsg_expired_session', 767 'tsg_user_last_login_location' 768 ]; 769 770 if (CANDEE_SERVER_AUTH_BRIDGE.getIframeAuthStorageKey()){ 771 keys.push(CANDEE_SERVER_AUTH_BRIDGE.getIframeAuthStorageKey()); 772 } 773 774 if (appId !== ''){ 775 keys.push('ledgers' + appId); 776 keys.push('tsg_checkoutform_' + appId); 777 keys.push('tsg_sightmap_' + appId); 778 keys.push('candee_last_order' + appId); 779 } 780 781 return keys; 782 }; 783 784 SHARED.clearAuthClientState = function(setSessionExpired){ 785 var storages = []; 786 var storageKeys = SHARED.getLogoutStorageKeys(); 787 var storagePrefixes = [ 788 'ledgers', 789 'candee_orders_v2_', 790 'candee_orders_history_', 791 'tsg_checkoutform_', 792 'tsg_sightmap_', 793 'candee_last_order' 794 ]; 795 796 var addStorage = function(storage){ 797 if (!storage){ 798 return; 799 } 800 801 if (storages.indexOf(storage) === -1){ 802 storages.push(storage); 803 } 804 }; 805 806 var removeKey = function(storage, key){ 807 if (!storage || typeof storage.removeItem !== 'function' || !key){ 808 return; 809 } 810 811 try { 812 storage.removeItem(key); 813 } catch (err) {} 814 }; 815 816 var collectKeys = function(storage){ 817 var keys = []; 818 819 if (!storage){ 820 return keys; 821 } 822 823 try { 824 if (typeof storage.key === 'function' && typeof storage.length !== 'undefined'){ 825 for (var i = 0; i < storage.length; i++){ 826 var storageKey = storage.key(i); 827 if (storageKey){ 828 keys.push(storageKey); 829 } 830 } 831 } else if (storage.allStorage && typeof storage.allStorage === 'object'){ 832 keys = Object.keys(storage.allStorage); 833 } 834 } catch (err) {} 835 836 return keys; 837 }; 838 839 addStorage(typeof LOCALSTORAGE !== 'undefined' ? LOCALSTORAGE : null); 840 addStorage(typeof localStorage !== 'undefined' ? localStorage : null); 841 addStorage(typeof sessionStorage !== 'undefined' ? sessionStorage : null); 842 843 storageKeys.forEach(function(storageKey){
844 storages.forEach(function(storage){ 845 removeKey(storage, storageKey); 846 }); 847 }); 848 849 storages.forEach(function(storage){ 850 collectKeys(storage).forEach(function(currentKey){ 851 var shouldRemove = false; 852 853 storagePrefixes.forEach(function(prefix){ 854 if (currentKey && currentKey.indexOf(prefix) === 0){ 855 shouldRemove = true; 856 } 857 }); 858 859 if (shouldRemove){ 860 removeKey(storage, currentKey); 861 } 862 }); 863 }); 864 865 if (typeof SHARED.clearOrdersCache === 'function'){ 866 SHARED.clearOrdersCache(); 867 } 868 869 CANDEE_SERVER_AUTH_BRIDGE.clearStoredIframeAuth(); 870 871 if (typeof CART !== 'undefined' && CART && typeof CART.removeCart === 'function'){ 872 CART.removeCart(); 873 } 874 875 if (setSessionExpired == true){ 876 try { 877 LOCALSTORAGE.setItem('tsg_expired_session', true); 878 } catch (err) {} 879 } 880 }; 881 882 SHARED.logout = function(setSessionExpired){ 883 var userDetails = (typeof USERS !== 'undefined' && USERS && typeof USERS.getUserDetails === 'function') ? USERS.getUserDetails() : false; 884 var email = (typeof SHARED.isset === 'function' && userDetails && SHARED.isset(userDetails.email_address)) ? userDetails.email_address : ''; 885 var googleData = { 886 facname: candee_js_variables.master_facility, 887 cat: 'CAS3-logout', 888 action: 'logout', 889 label: 'logout', 890 value: email 891 }; 892 893 if (typeof SHARED.showLoader === 'function'){ 894 SHARED.showLoader(); 895 } 896 897 if (typeof SHARED.post_gtag === 'function'){ 898 SHARED.post_gtag(JSON.stringify(googleData)); 899 } 900 901 SHARED.clearAuthClientState(setSessionExpired); 902 903 if (typeof candee_js_variables == 'object'){ 904 candee_js_variables.server_auth_authed = false; 905 } 906 907 var finishLogout = function(){ 908 SHARED.clearAuthClientState(setSessionExpired); 909 cQuery('#candeeUserLogout').css('display', 'none'); 910 cQuery('#candeeUserLogin').css('display', 'inline-block'); 911 912 if (typeof SHARED.closePopup === 'function'){ 913 SHARED.closePopup(); 914 } 915 916 window.location.reload(); 917 }; 918 919 var logoutRequest = CANDEE_SERVER_AUTH_BRIDGE.syncLogout(); 920 921 if (logoutRequest && typeof logoutRequest.always === 'function'){ 922 logoutRequest.always(function(){ 923 finishLogout(); 924 }); 925 } else { 926 finishLogout(); 927 } 928 }; 929 } 930}; 931 932window.CANDEE_SERVER_AUTH_BRIDGE = CANDEE_SERVER_AUTH_BRIDGE; 933 934cQuery(function(){ 935 CANDEE_SERVER_AUTH_BRIDGE.installSharedIframeRouting(); 936 CANDEE_SERVER_AUTH_BRIDGE.installSharedLogoutHardening(); 937 CANDEE_SERVER_AUTH_BRIDGE.init(); 938 CANDEE_SERVER_AUTH_BRIDGE.updateIframeAwareLinks(); 939 CANDEE_SERVER_AUTH_BRIDGE.updateIframeAwareDocumentLinks(); 940 941 cQuery(document).on('ajax_complete', function(){ 942 CANDEE_SERVER_AUTH_BRIDGE.updateIframeAwareDocumentLinks(); 943 }); 944});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.