-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton-helper.js
44 lines (40 loc) · 1.99 KB
/
button-helper.js
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
'use strict'
var keyname = 'SolidServerRootRedirectLink';
function register() {
alert(2); window.location.href = "/.account/login/password/register/";
}
document.addEventListener('DOMContentLoaded', async function() {
const authn = UI.authn
const authSession = UI.authn.authSession
if (!authn.currentUser()) await authn.checkUser();
let user = authn.currentUser();
// IF LOGGED IN: SET SolidServerRootRedirectLink. LOGOUT
if( user ) {
window.localStorage.setItem(keyname, user.uri);
await authSession.logout();
}
else {
let 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 {
let loginArea = document.getElementById('loginStatusArea');
let html = `<input type="button" onclick="window.location.href='/.account/login/password/register/'" value="Sign up" 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;">`
let 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";
const signUpButton = loginArea.querySelectorAll('input')[2];
signUpButton.style.display = "none";
}
}
})