diff --git a/dashboard/index.html b/dashboard/index.html
index 7ae9589..65a56e5 100644
--- a/dashboard/index.html
+++ b/dashboard/index.html
@@ -22,7 +22,7 @@
-
Material Design Lite
+ Dashboard
@@ -66,16 +66,29 @@
+
+
+
+
+
+
Admin Dashboard - Login
+
+
+ Please login to enter this website.
+
+
+
+
+
+
+
+
Unauthorized Login
+
+
+ You attempted to login with an improper account. If this is in error, please try reloading the page.
+
+
+
diff --git a/dashboard/script.js b/dashboard/script.js
index ed7702a..aae2fd6 100644
--- a/dashboard/script.js
+++ b/dashboard/script.js
@@ -1,32 +1,8 @@
function onLoad() {
startFirebase()
- displayProjects("all")
-}
-
-function displayProjects(status) {
- document.getElementById("projects").innerHTML = ""
- database = firebase.database().ref("projects");
- database.once('value', function (snapshot) {
- snapshot.forEach(function (child) {
- firebase.database().ref("projects/" + child["key"]).on('value', function (data) {
- var data1 = data.val();
- var a = document.createElement("div")
- if (data1["link"] == "") {
- a.innerHTML = '
' + data1["title"].replace(/,/g, ".") + '
' + data1["status"] + '
' + data1["description"] + '
'
- //a.innerHTML = "" + data1["title"].replace(/,/g, ".") + " " + data1["status"] + " |
| " + data1["description"] + " |
"
- } else {
- a.innerHTML = '
' + data1["title"].replace(/,/g, ".") + '
' + data1["status"] + '
' + data1["description"] + '
'
- // a.innerHTML = " |
| " + data1["description"] + " |
"
- }
-
- if (status === "all") {
- document.getElementById("projects").appendChild(a)
- } else if (data1["status"] === status) {
- document.getElementById("projects").appendChild(a)
- }
- })
- })
- });
+ document.getElementById("main_content").style.display = "none";
+ document.getElementById("unauthorized").style.display = "none";
+ checkLogin()
}
// Starts Firebase
@@ -43,6 +19,87 @@ function startFirebase() {
firebase.initializeApp(config);
}
+// Make completly sure user is authenticated.
+function verify() {
+ firebase.auth().onAuthStateChanged(function (user) {
+ if (user) {
+ readData("users", function (array) {
+ if (array[firebase.auth().currentUser.uid]) {
+ // Do nothing
+ } else {
+ window.location.href = "unauthorized.html"
+ }
+ });
+ } else {
+ window.location.href = "unauthorized.html"
+ }
+ })
+}
+
+// Firebase Check Log In Status
+function checkLogin() {
+ firebase.auth().onAuthStateChanged(function (user) {
+ if (user) {
+ readData("users", function (array) {
+ if (array[firebase.auth().currentUser.uid]) {
+ document.getElementById("firebase_name").innerText = firebase.auth().currentUser.displayName
+ document.getElementById("firebase_email").innerText = firebase.auth().currentUser.email
+ document.getElementById("firebase_photo").setAttribute("src", firebase.auth().currentUser.photoURL)
+ document.getElementById("main_content").style.display = "block";
+ document.getElementById("login_container").style.display = "none";
+ document.getElementById("unauthorized").style.display = "none";
+ } else {
+ document.getElementById("main_content").innerHTML = ""
+ document.getElementById("login_container").innerHTML = ""
+ document.getElementById("unauthorized").style.display = "block";
+ }
+ })
+ } else {
+ document.getElementById("main_content").style.display = "none";
+ document.getElementById("login_container").style.display = "block";
+ document.getElementById("unauthorized").style.display = "none";
+ }
+ })
+}
+
+// Firebase Log In
+function logIn() {
+ firebase.auth().setPersistence("local")
+ // No user is signed in.
+ var provider = new firebase.auth.GoogleAuthProvider();
+ firebase.auth().signInWithPopup(provider).then(function (result) {
+ // This gives you a Google Access Token. You can use it to access the Google API.
+ var token = result.credential.accessToken;
+ // The signed-in user info.
+ var user = result.user;
+ readData("users", function (array) {
+ checkLogin();
+ });
+ // ...
+ }).catch(function (error) {
+ // Handle Errors here.
+ var errorCode = error.code;
+ var errorMessage = error.message;
+ // The email of the user's account used.
+ var email = error.email;
+ // The firebase.auth.AuthCredential type that was used.
+ var credential = error.credential;
+ console.log(errorCode)
+ console.log(errorMessage)
+ // ...
+ });
+}
+
+// Firebase Log Out
+function logOut() {
+ firebase.auth().signOut().then(function () {
+ checkLogin();
+ }, function (error) {
+ console.log("ERROR")
+ console.log(error)
+ });
+}
+
// Firebase Interaction Scripts
function readData(ref, callback) {
var nextformation = firebase.database().ref(ref);
diff --git a/dashboard/style.css b/dashboard/style.css
index 2b21250..5a3002c 100644
--- a/dashboard/style.css
+++ b/dashboard/style.css
@@ -1,6 +1,21 @@
-.project-card {
- width: 98.5%;
- margin: 10px;
+.login-card {
+ position: absolute;
+ top: 0; left: 0; bottom: 0; right: 0;
+ margin: auto;
+ height: 20px;
+ text-align: center;
+}
+
+.unauthorized-card {
+ position: absolute;
+ top: 0; left: 0; bottom: 0; right: 0;
+ margin: auto;
+ height: 20px;
+ text-align: center;
+}
+
+#login_container {
+ height: 100%;
}
.active {color: green;}
diff --git a/legacy/js/script.js b/legacy/js/script.js
index 6d452eb..669c81d 100644
--- a/legacy/js/script.js
+++ b/legacy/js/script.js
@@ -409,7 +409,7 @@ function logIn() {
console.log(errorMessage)
// ...
});
-}
+}
// Firebase Log Out
function logOut() {
diff --git a/project_explorer/index.html b/project_explorer/index.html
index 7ae9589..65203e4 100644
--- a/project_explorer/index.html
+++ b/project_explorer/index.html
@@ -22,7 +22,7 @@
- Material Design Lite
+ Project Explorer