-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathindex-buttons.mjs
More file actions
44 lines (41 loc) · 1.97 KB
/
index-buttons.mjs
File metadata and controls
44 lines (41 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ESM version of index-buttons.js
/* global SolidLogic */
'use strict'
const keyname = 'SolidServerRootRedirectLink'
/* function register () {
alert(2)
window.location.href = '/register'
} */
document.addEventListener('DOMContentLoaded', async function () {
const authn = SolidLogic.authn
const authSession = SolidLogic.authSession
if (!authn.currentUser()) await authn.checkUser()
const user = authn.currentUser()
// IF LOGGED IN: SET SolidServerRootRedirectLink. LOGOUT
if (user) {
window.localStorage.setItem(keyname, user.uri)
await authSession.logout()
} else {
const webId = window.localStorage.getItem(keyname)
// IF NOT LOGGED IN AND COOKIE EXISTS: REMOVE COOKIE, HIDE WELCOME, SHOW LINK TO PROFILE
if (webId) {
window.localStorage.removeItem(keyname)
document.getElementById('loggedIn').style.display = 'block'
document.getElementById('loggedIn').innerHTML = `<p>Your WebID is : <a href="${webId}">${webId}</a>.</p> <p>Visit your profile to log into your Pod.</p>`
// IF NOT LOGGED IN AND COOKIE DOES NOT EXIST
// SHOW WELCOME, SHOW LOGIN BUTTON
// HIDE LOGIN BUTTON, ADD REGISTER BUTTON
} else {
const loginArea = document.getElementById('loginStatusArea')
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;">`
const span = document.createElement('span')
span.innerHTML = html
loginArea.appendChild(span)
loginArea.appendChild(UI.login.loginStatusBox(document, null, {}))
const logInButton = loginArea.querySelectorAll('input')[1]
logInButton.value = 'Log in to see your WebID'
const signUpButton = loginArea.querySelectorAll('input')[2]
signUpButton.style.display = 'none'
}
}
})