|
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 | +document.addEventListener('DOMContentLoaded', async function () { |
| 5 | + const authn = UI.authn |
| 6 | + const authSession = UI.authn.authSession |
11 | 7 |
|
12 | | - if (!authn.currentUser()) await authn.checkUser(); |
13 | | - let user = authn.currentUser(); |
| 8 | + if (!authn.currentUser()) await authn.checkUser() |
| 9 | + const user = authn.currentUser() |
14 | 10 |
|
15 | 11 | // IF LOGGED IN: SET SolidServerRootRedirectLink. LOGOUT |
16 | 12 | if (user) { |
17 | | - window.localStorage.setItem(keyname, user.uri); |
18 | | - await authSession.logout(); |
| 13 | + window.localStorage.setItem(keyname, user.uri) |
| 14 | + await authSession.logout() |
19 | 15 | } else { |
20 | | - let webId = window.localStorage.getItem(keyname); |
| 16 | + const webId = window.localStorage.getItem(keyname) |
21 | 17 | // IF NOT LOGGED IN AND COOKIE EXISTS: REMOVE COOKIE, HIDE WELCOME, SHOW LINK TO PROFILE |
22 | 18 | 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 | | - } |
27 | | - // IF NOT LOGGED IN AND COOKIE DOES NOT EXIST |
28 | | - // SHOW WELCOME, SHOW LOGIN BUTTON |
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"; |
| 19 | + window.localStorage.removeItem(keyname) |
| 20 | + document.getElementById('loggedIn').style.display = 'block' |
| 21 | + document.getElementById('loggedIn').innerHTML = `<p>Your WebID is : <a href="${webId}">${webId}</a>.</p> <p>Visit your profile to log into your Pod.</p>` |
| 22 | + // IF NOT LOGGED IN AND COOKIE DOES NOT EXIST |
| 23 | + // SHOW WELCOME, SHOW LOGIN BUTTON |
| 24 | + // HIDE LOGIN BUTTON, ADD REGISTER BUTTON |
| 25 | + } else { |
| 26 | + const loginArea = document.getElementById('loginStatusArea') |
| 27 | + 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;">` |
| 28 | + const span = document.createElement('span') |
| 29 | + span.innerHTML = html |
| 30 | + loginArea.appendChild(span) |
| 31 | + loginArea.appendChild(UI.login.loginStatusBox(document, null, {})) |
| 32 | + const logInButton = loginArea.querySelectorAll('input')[1] |
| 33 | + logInButton.value = 'Log in to see your WebID' |
| 34 | + const signUpButton = loginArea.querySelectorAll('input')[2] |
| 35 | + signUpButton.style.display = 'none' |
41 | 36 | } |
42 | 37 | } |
43 | | -}); |
| 38 | +}) |
0 commit comments