1/* 2 * Gets userId from JWTCookie 3 * userId is used to get user name from paywall provider 4 * Will work for customers of FSOnline 5 * Log out buttons redirects to api/paywall/logout 6 * Is used in clientData in function toggleAuthenticatedContent 7 * Must be initiated in header template for each customer - see seilmagasinet for example of implementation 8*/ 9 10if (!window.Dac) window.Dac = {}; 11window.Dac.Paywall = class { 12 13 constructor() { 14 if (window.Dac && window.Dac.JWTCookie) { 15 this.JWTCookie = new window.Dac.JWTCookie({ debug: false }); 16 } 17 } 18 19 async getUserName() { 20 let userId = ''; 21 22 if (this.JWTCookie.isAuthenticated()) { 23 userId = await this.JWTCookie.get('sub'); 24 25 if (!userId || !userId.length) { 26 return new Promise((resolve) => { 27 resolve(''); 28 }); 29 } 30 } else { 31 return new Promise((resolve) => { 32 resolve(false); 33 }); 34 } 35 36 try { 37 const responseFromApi = await fetch(`https://fsonline.no/service/xhrlookup/${ userId }`).then((response) => { 38 if (response.status >= 400 && response.status < 600) { 39 console.error('Bad response from server', response.status); 40 return false; 41 } 42 return response.json(); 43 }); 44 45 return responseFromApi.fullName === 'N/A' ? '' : responseFromApi.fullName; 46 } catch (error) { 47 console.error('Network error', error); 48 return false; 49 } 50 } 51 52 updateDOM(authenticated, username = '', greeting = '') { 53 const isUserAuthenticadedClass = authenticated ? 'dac-paywall-authenticated' : 'dac-paywall-not-authenticated'; 54 const paywallAuthenticatedItemsToShow = document.querySelectorAll(`.${ isUserAuthenticadedClass }`); 55 56 paywallAuthenticatedItemsToShow.forEach((authItem) => { 57 if (username.length && authItem.firstElementChild && !authItem.classList.contains('dac-logout-paywall-btn')) { 58 authItem.firstElementChild.innerText = greeting + username; 59 } 60 authItem.classList.remove(isUserAuthenticadedClass); 61 }); 62 } 63 64};
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.