front end authentication

trunk
HeNine 3 years ago
parent 74155a7f6c
commit fb2132dd16

@ -51,7 +51,8 @@
<!-- data-logo_alignment="left">--> <!-- data-logo_alignment="left">-->
<!--</div>--> <!--</div>-->
<div id="googleLoginButton"></div> <div id="googleLoginButton" style="display: none"></div>
<div id="logout" style="display: none"><a href="javascript:doLogout()">Log out</a></div>
<div id="speakers"> <div id="speakers">
<label for="speaker_input">Speakers</label><input id="speaker_input"> <label for="speaker_input">Speakers</label><input id="speaker_input">

@ -32,6 +32,16 @@ function pageReady() {
.then(fillLineInfo) .then(fillLineInfo)
.then(initializePlayer); .then(initializePlayer);
handleLoginState();
}
function handleLoginState() {
if (document.cookie.split('; ').find(row => row.startsWith('credentials='))) {
document.getElementById("logout").style.display = "";
} else {
document.getElementById("googleLoginButton").style.display = "";
}
} }
function doGoogle() { function doGoogle() {
@ -47,13 +57,20 @@ function doGoogle() {
google.accounts.id.prompt(); // also display the One Tap dialog google.accounts.id.prompt(); // also display the One Tap dialog
} }
function doLogout() {
document.cookie = `credentials=;expires=Thu, 01 Jan 1970 00:00:01 GMT`;
document.getElementById("googleLoginButton").style.display = "";
document.getElementById("logout").style.display = "none";
}
function loggedIn(response) { function loggedIn(response) {
// credentials = parseJwt(response.credential) // credentials = parseJwt(response.credential)
// TODO: add specifiers // TODO: add cookie storage specifiers
document.cookie = `credentials=${response.credential}`; document.cookie = `credentials=${response.credential}`;
document.getElementById("googleLoginButton").style.display = "none"; document.getElementById("googleLoginButton").style.display = "none";
document.getElementById("logout").style.display = "";
console.log(response); console.log(response);
} }

Loading…
Cancel
Save