From fb2132dd16a4dcc2ef18a7eda63ff4d01e1aa606 Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Sat, 13 Nov 2021 09:49:34 +0100 Subject: [PATCH] front end authentication --- professor/professor.html | 3 ++- professor/script.js | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/professor/professor.html b/professor/professor.html index ead92a1..1a9c9ea 100644 --- a/professor/professor.html +++ b/professor/professor.html @@ -51,7 +51,8 @@ -
+ +
diff --git a/professor/script.js b/professor/script.js index 604ef74..8b8d056 100644 --- a/professor/script.js +++ b/professor/script.js @@ -32,6 +32,16 @@ function pageReady() { .then(fillLineInfo) .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() { @@ -47,13 +57,20 @@ function doGoogle() { 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) { // credentials = parseJwt(response.credential) - // TODO: add specifiers + // TODO: add cookie storage specifiers document.cookie = `credentials=${response.credential}`; document.getElementById("googleLoginButton").style.display = "none"; + document.getElementById("logout").style.display = ""; console.log(response); }