diff --git a/contact.html b/contact.html index 504328f..fe1b95a 100644 --- a/contact.html +++ b/contact.html @@ -1,22 +1,26 @@ LAX18's Homepage | Contact + + - +
diff --git a/dashboard.html b/dashboard.html new file mode 100644 index 0000000..123ef3e --- /dev/null +++ b/dashboard.html @@ -0,0 +1,55 @@ + + +LAX18's Homepage | Admin Dashboard + + + + + + + + + + + +
+ + +
+

Admin Dashboard

+ Add Project:
+ Title:
+
+ Link:
+
+ Status:
+
+ Description:
+
+ +

+ Select Project to Edit:
+ + + diff --git a/index.html b/index.html index dedaf07..f31ea31 100644 --- a/index.html +++ b/index.html @@ -3,24 +3,28 @@ LAX18's Homepage + + - +
diff --git a/js/script.js b/js/script.js new file mode 100644 index 0000000..c0af984 --- /dev/null +++ b/js/script.js @@ -0,0 +1,141 @@ +// Project Submit +function submitProject() { + var data = { + title: document.getElementById("new-project-title").value, + link: document.getElementById("new-project-link").value, + status: document.getElementById("new-project-status").value, + description: document.getElementById("new-project-description").value + } + firebase.database().ref("projects/"+document.getElementById("new-project-title").value).set(data) +} + +// Pull Project List and Display in Option +function projectList() { + database = firebase.database().ref("projects"); + database.once('value', function(snapshot) { + snapshot.forEach(function(child) { + var a = document.createElement("option") + a.setAttribute("value",child["key"]) + a.innerHTML = child["key"] + document.getElementById("project-list").appendChild(a) + }) + }); +} + + +// 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" + } + }) +} + + +// On pages load +function onLoad() { + document.getElementById("logoutbutton").style.display = "none" + startFirebase(); + checkLogin(); + } +// Starts Firebase +function startFirebase() { + // Initialize Firebase + var config = { + apiKey: "AIzaSyBG5-wv3bpeiUjR6BH5GXamqPlH1arXt8Y", + authDomain: "homepage-projects-3d870.firebaseapp.com", + databaseURL: "https://homepage-projects-3d870.firebaseio.com", + projectId: "homepage-projects-3d870", + storageBucket: "homepage-projects-3d870.appspot.com", + messagingSenderId: "487531629040" + }; + firebase.initializeApp(config); +} + +// 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("loginbutton").innerHTML = "Dashboard" + var logoutnode = document.createElement("li"); + document.getElementById("logoutbutton").style.display = "block" + } else { + document.getElementById("loginbutton").innerHTML = "Welcome, "+firebase.auth().currentUser.displayName + document.getElementById("logoutbutton").style.display = "block" + } + })} else { + document.getElementById("loginbutton").innerHTML = "Log In" + document.getElementById("logoutbutton").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); + nextformation.on("value", function(data) { + var array = data.val(); + callback(array) + }); +} +// global read data and place on page function +function setData(ref, element, read1) { + var array = readData(ref, function(array) { + document.getElementById(element).innerHTML = array[read1] + }); +} + +// Firebase Interaction Scripts +function sendData(ref, data) { + var database = firebase.database(); + firebase.database().ref(ref).set(data); +} \ No newline at end of file diff --git a/programs.html b/programs.html index 2d5e8a5..d216358 100644 --- a/programs.html +++ b/programs.html @@ -1,6 +1,8 @@ LAX18's Homepage | Programs + + @@ -9,18 +11,20 @@ td {border-bottom-style: solid;} tr {margin-bottom: 10px;} - +
diff --git a/projects.html b/projects.html index 53b1215..a13595e 100644 --- a/projects.html +++ b/projects.html @@ -1,6 +1,8 @@ LAX18's Homepage | Projects + + @@ -8,18 +10,20 @@ - +
diff --git a/unauthorized.html b/unauthorized.html new file mode 100644 index 0000000..f320465 --- /dev/null +++ b/unauthorized.html @@ -0,0 +1,11 @@ + + + Unauthorized Access + + +

+ ERROR
+ UNAUTHORIZED ACCESS +

+ + \ No newline at end of file