The page may have moved, you may have mistyped the address, or followed a bad link.
Visit our homepage, or search for whatever you were looking for…
‘; //`Welcome ${user.name}!`; mobileButton.innerHTML = ‘
Logout
‘; //`Welcome ${user.name}!`; loginBtn.onclick = () => bcApp.logout(); mobileButton.onclick = () => bcApp.logout(); } else { loginBtn.innerHTML = ‘
Login
‘; loginBtn.onclick = () => bcApp.login(); } //create content for menu for logged in user const menu = document.getElementById(‘LIWA’); if (state) { //menu.innerHTML = ‘
Welcome, ‘ + user.name + ‘!
‘; } }; bcApp.eraseUserData = async () => { bcApp.debug(‘chris erasing data’); localStorage.setItem(‘1337’,”); bcApp.articleCount = 0; bcApp.userEmail = ”; bcApp.auth0Email = ”; bcApp.userFirstName = ”; bcApp.lastArticleTitles = []; bcApp.lastArticleUrls = []; bcApp.subscriberAuth = 0; bcApp.profile = null; bcApp.user = null; bcApp.lastLogin = null; bcApp.isAuthenticated = false; bcApp.nonSubEvent = 0; bcApp.authorizedSubEvent = 0; bcApp.regwallEvent; return Promise.resolve(); // This returns a promise that is immediately resolved } /** * Starts the authentication flow */ bcApp.login = async (targetUrl) => { //popup try { await bcApp.auth0Client.loginWithPopup(); bcApp.auth0Client.getUser().then(async user => { if (user) { await bcApp.eraseUserData(); await bcApp.loadBCProfile(); await bcApp.bcSetVariables(); await bcApp.updateUI(true); //this fixes our bc issue of not refreshing dialogues location.reload(); } else { bcApp.debug(‘chris User is not logged in correctly’); } }).catch(error => { bcApp.debug(‘chris Failed to get user data:’, error); }); // if (bcApp.user) { // bcApp.debug(‘chris: user is logged in refresh page’); // // do a reload until we figure out a different BC api to use // location.reload(); // //bcApp.bcFireEvent(‘auth0LoggedIn’); // //erase storage and recheck entitlements since they just logged in // // await bcApp.loadBCProfile(); // // await bcApp.bcSetVariables(); // // bcApp.updateUI(true); // // bcApp.bcEvent(bcApp.user); // } } catch (error) { if (error instanceof auth0.PopupTimeoutError) { // custom logic to inform user to retry error.popup.close(); bcApp.bcFireEvent(‘auth0LoggedOut’); } bcApp.debug(“chris: Login failed”, error); } }; /** * Executes the logout flow */ bcApp.logout = async () => { try { bcApp.debug(“Logging out”); if (typeof Connext !== “undefined” && Connext !== null && typeof Connext.Storage !== “undefined” && typeof Connext.Storage.GetUserData !== “undefined”) { var userData = Connext.Storage.GetUserData(); if (typeof userData.Email !== “undefined” && userData.Email !== null && userData.Email !== “”) { Connext.Logout(); } } await bcApp.eraseUserData(); await bcApp.auth0Client.logout({ logoutParams: { returnTo: window.location.origin } }); } catch (err) { bcApp.debug(“Log out failed”, err); } }; /** * Retrieves the auth configuration from the server */ //const fetchAuthConfig = () => fetch(“/auth_config.json”); /** * Initializes the Auth0 client */ bcApp.configureClient = async () => { bcApp.auth0Client = await auth0.createAuth0Client({ domain: ‘gazette-prod.us.auth0.com’, clientId: bcApp.auth0ClientId, cacheLocation: ‘localstorage’, useRefreshTokens: true }); bcApp.debug(‘chris: 3 – auth0 client loaded’); return; }; /** * Checks to see if the user is authenticated. If so, `fn` is executed. Otherwise, the user * is prompted to log in * @param {*} fn The function to execute if the user is logged in */ // will be used later // bcApp.requireAuth = async (fn, targetUrl) => { // bcApp.isAuthenticated = await bcApp.auth0Client.isAuthenticated(); // if (bcApp.isAuthenticated) { // return fn(); // } // return bcApp.login(targetUrl); // }; bcApp.createUI = async (state) => { // create UI const user = await bcApp.auth0Client.getUser(); bcApp.debug(‘creating UI for user: ‘,user); bcApp.debug(‘chris is making some UIiiiiii’, state); // todo: do we need this? // const loginbutton = document.createElement(‘button’); // // Set the text content of the button // loginbutton.textContent = ‘Login’; // // Get the div with the class pull-right // const div = document.querySelector(‘.pull-right’); // // Add the button to the div // div.appendChild(loginbutton); // Create a new button element const button = document.createElement(‘button’); button.id = ‘newMenuButton’; button.classList.add(‘btn’); button.style.backgroundColor = ‘rgb(28, 95, 174)’; button.style.width = ‘120px’; button.style.color = ‘white’; button.style.marginTop = ’10px’; button.style.marginRight = ’20px’; button.style.padding = ‘4px’; function createStyledButton(id, textContent) { const button = document.createElement(‘button’); button.id = id; button.textContent = textContent; button.classList.add(‘btn’); button.style.backgroundColor = ‘rgb(28, 95, 174)’; button.style.width = ‘120px’; button.style.color = ‘white’; button.style.marginTop = ’10px’; button.style.marginRight = ’20px’; button.style.display = ‘none’; return button; }; // Slide menu button const tempSlideMenuBtn1 = createStyledButton(‘newMenuSlideButton’, ‘Menu 1’); // mobile slide menu button const tempSlideMenuBtn2 = createStyledButton(‘newMenuSlideButton_mobile’, ‘Menu 2’); // my account button const tempMyAccountBtn = createStyledButton(‘newMyAccountButton’, ‘My Account’); //mobile menu button const mobileButton = document.createElement(‘button’); mobileButton.id = ‘newMobileMenuButton’; mobileButton.classList.add(‘btn’); mobileButton.style.backgroundColor = ‘rgb(28, 95, 174)’; mobileButton.style.width = ‘120px’; mobileButton.style.display = ‘flex’; mobileButton.style.color = ‘white’; mobileButton.style.marginTop = ’10px’; mobileButton.style.marginLeft = ’20px’; mobileButton.style.marginbottom = ‘-15px’; // Set the text content of the button const btnText = state ? ‘Logout’ : ‘Login’; button.innerHTML = ‘
‘ + btnText + ‘
‘; tempSlideMenuBtn1.innerHTML = ‘ Menu ‘; mobileButton.innerHTML = ‘
‘ + btnText + ‘
‘; button.onclick = () => { if (state) { bcApp.logout(); } else { bcApp.login(); } }; mobileButton.onclick = () => { if (state) { bcApp.logout(); } else { bcApp.login(); } }; tempMyAccountBtn.onclick = () => { location.href = ‘https://myaccount.gazette.com/’; } tempSlideMenuBtn1.onclick = () => { bcApp.debug(‘chris clicked’); var fullPageDiv = document.getElementById(‘gazSliderMenu’); if (fullPageDiv.classList.contains(‘gone’)) { fullPageDiv.classList.remove(‘gone’); fullPageDiv.classList.add(‘view’); } else { fullPageDiv.classList.remove(‘view’); fullPageDiv.classList.add(‘gone’); } }; // Add event listener for clicks outside the menu document.addEventListener(‘click’, function(event) { var fullPageDiv = document.getElementById(‘gazSliderMenu’); if (!(fullPageDiv.contains(event.target) || event.target.id === ‘newMenuSlideButton’)) { if (fullPageDiv.classList.contains(‘view’)) { fullPageDiv.classList.remove(‘view’); fullPageDiv.classList.add(‘gone’); } } }); // button.innerHTML = ”+ ‘
‘ + btnText + ‘
‘; // // Get the div with the class pull-right const menu = document.querySelector(‘#navbar-collapse .pull-right’); const mobileMenu = document.querySelector(‘#tncms-region-nav-mobile-nav-left’); // // Add the button to the div menu.appendChild(button); //pre-launch menu.appendChild(tempMyAccountBtn); //menu.appendChild(tempSlideMenuBtn1); mobileMenu.prepend(mobileButton); //pre-launch //mobileMenu.prepend(tempSlideMenuBtn2); // Clone the element const cloneElement = tempMyAccountBtn.cloneNode(true); // ‘true’ means clone the element and its children cloneElement.classList.add(‘mobileMyAccountBtn’); cloneElement.onclick = () => { location.href = ‘https://myaccount.gazette.com/’; } mobileMenu.prepend(cloneElement); return; } // Will run when page finishes loading window.onload = async () => { bcApp.debug(‘chris: 2 – onload start’); await bcApp.configureClient(); bcApp.debug(‘chris: 4 – continue onload’); bcApp.isAuthenticated = await bcApp.auth0Client.isAuthenticated(); async function waitForPaywallPluginReady(timeout = 30000) { const startTime = Date.now(); bcApp.debug(‘chris waiting for plugin to be ready’); while (true) { if (window.paywallPluginReady === 1) { bcApp.debug(‘chris pluginready wait done’); return true; // paywallPluginReady is 1, return true } else if (Date.now() – startTime >= timeout) { bcApp.debug(‘chris pluginready wait timeout..should probably refresh bc’); return false; // timeout expired, return false } await new Promise(resolve => setTimeout(resolve, 100)); // Wait for 100ms } } async function bcStart() { return new Promise(async (resolve) => { // get blueconic data ready // Is BlueConic loaded? if (typeof window.blueConicClient !== ‘undefined’ && typeof window.blueConicClient.event !== ‘undefined’ && typeof window.blueConicClient.event.subscribe !== ‘undefined’) { // BlueConic is loaded, now we can do API things await bcApp.loadBCProfile(); resolve(); } else { // Not yet loaded; wait for the “onBlueConicLoaded” event window.addEventListener(‘onBlueConicLoaded’, async function () { // BlueConic is loaded, now we can do API things bcApp.debug(‘chris event listener fired’); await bcApp.loadBCProfile(); resolve(); }, false); } }); } if (bcApp.isAuthenticated) { bcApp.bcFireEvent(‘auth0LoggedIn’); } else { bcApp.bcFireEvent(‘auth0LoggedOut’); } document.addEventListener(‘profileLoaded’, function() { bcApp.debug(“chris says profileLoaded event”); bcApp.entitlementCheck(); }); await waitForPaywallPluginReady(); await bcStart(); bcApp.debug(‘chris: 9 – window loaded / blueconic loaded / profile loaded’); if (bcApp.isAuthenticated) { bcApp.debug(‘chris: 10 – auth0 authenticated check’); await bcApp.bcSetVariables(); //pre-launch bcApp.createUI(bcApp.isAuthenticated); bcApp.debug(“chris = User is authenticated”); //window.history.replaceState({}, document.title, window.location.pathname); return; } else { bcApp.debug(‘chris: 11 – auth0 not authenticated check’); } bcApp.debug(“chris = User not authenticated”); //pre-launch bcApp.createUI(bcApp.isAuthenticated); bcApp.bcFireEvent(‘paywall_code_ready’); // this is the last thing to happen, so now check if we should fire regwall if (bcApp.meterCount >= “2” && !bcApp.userEmail && !bcApp.subscriberAuth) { // regwall! fire bcApp.bcEventPaywall(‘regwallStart’); } else if (bcApp.meterCount >= “2” && bcApp.userEmail && !bcApp.subscriberAuth) { //we have their email and they have no subscription so they should get a paywall instead of regwall bcApp.debug(‘chris: user already paywalled, no regwall only paywall’); bcApp.bcEventPaywall(‘nonSub’); } bcApp.debug(‘chris; should regwall fire: ‘, bcApp.meterCount, bcApp.userEmail,!bcApp.subscriberAuth); const query = window.location.search; const shouldParseResult = query.includes(“code=”) && query.includes(“state=”); if (shouldParseResult) { bcApp.debug(“chris > Parsing redirect”); try { const result = await bcApp.auth0Client.handleRedirectCallback(); if (result.appState && result.appState.targetUrl) { //showContentFromUrl(result.appState.targetUrl); } bcApp.debug(“Logged in!”); } catch (err) { bcApp.debug(“Error parsing redirect:”, err); } //window.history.replaceState({}, document.title, “/”); } //Engage data checks for when switch over this can be removed after a few weeks function waitForObject(objectName, callback, interval = 100, timeout = 180000) { const checkInterval = setInterval(() => { if (typeof window[objectName] !== ‘undefined’) { clearInterval(checkInterval); clearTimeout(timeoutId); callback(window[objectName]); } }, interval); const timeoutId = setTimeout(() => { clearInterval(checkInterval); bcApp.debug(`chris Stopped checking for ${objectName} after ${timeout / 1000} seconds`); }, timeout); } // Example usage: waitForObject(‘Connext’, (Connext) => { bcApp.debug(‘chris Connext is now defined:’, Connext); // You can add additional logic to execute once Connext is defined if (typeof Connext !== “undefined” && typeof Connext.Storage.GetUserData().DigitalAccess.IsAuthorized !== “undefined”) { if (Connext.Storage.GetUserData().DigitalAccess.IsAuthorized) { bcApp.debug(‘chris user is authorized via engage’); // we are only doing a simple check so the user doesn’t hit the paywall, until the other checks kick in in the future bcApp.subscriberAuth = 1; bcApp.profile.setValue(’email’, Connext.Storage.GetUserData().Email ); bcApp.profile.setValue(bcApp.authorizedProfile2, 1); bcApp.profile.setValue(‘auth0_login_date’, new Date()); //pre-launch bcApp.updateUI(true); //pre-launch bcApp.login(); blueConicClient.profile.updateProfile(this, function() { // Profile is now persistent bcApp.debug(‘chris connext updated profile’); bcApp.blueConicClient.handlePageView(); }); } else { bcApp.debug(‘chris user is not authorized via engage’); } } else { bcApp.debug(‘chris not a connext subscriber’); } }); };
Source