|
1 | 1 | // ESM version of index-buttons.js |
2 | | -'use strict'; |
3 | | -const keyname = 'SolidServerRootRedirectLink'; |
4 | | -function register() { |
5 | | - alert(2); |
6 | | - window.location.href = "/register"; |
7 | | -} |
8 | | -document.addEventListener('DOMContentLoaded', async function() { |
9 | | - const authn = UI.authn; |
10 | | - const authSession = UI.authn.authSession; |
| 2 | +'use strict' |
| 3 | +const keyname = 'SolidServerRootRedirectLink' |
| 4 | +/* function register () { |
| 5 | + alert(2) |
| 6 | + window.location.href = '/register' |
| 7 | +} */ |
| 8 | +document.addEventListener('DOMContentLoaded', async function () { |
| 9 | + const authn = UI.authn |
| 10 | + const authSession = UI.authn.authSession |
11 | 11 |
|
12 | | - if (!authn.currentUser()) await authn.checkUser(); |
13 | | - let user = authn.currentUser(); |
| 12 | + if (!authn.currentUser()) await authn.checkUser() |
| 13 | + const user = authn.currentUser() |
14 | 14 |
|
15 | 15 | // IF LOGGED IN: SET SolidServerRootRedirectLink. LOGOUT |
16 | 16 | if (user) { |
17 | | - window.localStorage.setItem(keyname, user.uri); |
18 | | - await authSession.logout(); |
| 17 | + window.localStorage.setItem(keyname, user.uri) |
| 18 | + await authSession.logout() |
19 | 19 | } else { |
20 | | - let webId = window.localStorage.getItem(keyname); |
| 20 | + const webId = window.localStorage.getItem(keyname) |
21 | 21 | // IF NOT LOGGED IN AND COOKIE EXISTS: REMOVE COOKIE, HIDE WELCOME, SHOW LINK TO PROFILE |
22 | 22 | if (webId) { |
23 | | - window.localStorage.removeItem(keyname); |
24 | | - document.getElementById('loggedIn').style.display = "block"; |
25 | | - document.getElementById('loggedIn').innerHTML = `<p>Your WebID is : <a href="${webId}">${webId}</a>.</p> <p>Visit your profile to log into your Pod.</p>`; |
26 | | - } |
| 23 | + window.localStorage.removeItem(keyname) |
| 24 | + document.getElementById('loggedIn').style.display = 'block' |
| 25 | + document.getElementById('loggedIn').innerHTML = `<p>Your WebID is : <a href="${webId}">${webId}</a>.</p> <p>Visit your profile to log into your Pod.</p>` |
| 26 | + |
27 | 27 | // IF NOT LOGGED IN AND COOKIE DOES NOT EXIST |
28 | 28 | // SHOW WELCOME, SHOW LOGIN BUTTON |
29 | 29 | // HIDE LOGIN BUTTON, ADD REGISTER BUTTON |
30 | | - else { |
31 | | - let loginArea = document.getElementById('loginStatusArea'); |
32 | | - let html = `<input type="button" onclick="window.location.href='/register'" value="Register to get a Pod" class="register-button" style="padding: 1em; border-radius:0.2em; font-size: 100%;margin: 0.75em 0 0.75em 0.5em !important; padding: 0.5em !important;background-color: #efe;">`; |
33 | | - let span = document.createElement("span"); |
34 | | - span.innerHTML = html; |
35 | | - loginArea.appendChild(span); |
36 | | - loginArea.appendChild(UI.login.loginStatusBox(document, null, {})); |
37 | | - const logInButton = loginArea.querySelectorAll('input')[1]; |
38 | | - logInButton.value = "Log in to see your WebID"; |
39 | | - const signUpButton = loginArea.querySelectorAll('input')[2]; |
40 | | - signUpButton.style.display = "none"; |
| 30 | + } else { |
| 31 | + const loginArea = document.getElementById('loginStatusArea') |
| 32 | + const html = `<input type="button" onclick="window.location.href='/register'" value="Register to get a Pod" class="register-button" style="padding: 1em; border-radius:0.2em; font-size: 100%;margin: 0.75em 0 0.75em 0.5em !important; padding: 0.5em !important;background-color: #efe;">` |
| 33 | + const span = document.createElement('span') |
| 34 | + span.innerHTML = html |
| 35 | + loginArea.appendChild(span) |
| 36 | + loginArea.appendChild(UI.login.loginStatusBox(document, null, {})) |
| 37 | + const logInButton = loginArea.querySelectorAll('input')[1] |
| 38 | + logInButton.value = 'Log in to see your WebID' |
| 39 | + const signUpButton = loginArea.querySelectorAll('input')[2] |
| 40 | + signUpButton.style.display = 'none' |
41 | 41 | } |
42 | 42 | } |
43 | | -}); |
| 43 | +}) |
0 commit comments