diff --git a/back/backend/views.py b/back/backend/views.py index 21ab7d5..70e3f79 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -139,6 +139,7 @@ def reports(request): queryset = Report.objects.all() for i in queryset: data = { + "report_pk": i.id, "title": i.title, "date_created": i.date_created, "submitted": i.submitted, diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 7c7ffb7..2a1a553 100644 Binary files a/back/db.sqlite3 and b/back/db.sqlite3 differ diff --git a/front/static/js/login.js b/front/static/js/login.js index 8269c99..20b411d 100644 --- a/front/static/js/login.js +++ b/front/static/js/login.js @@ -1,8 +1,3 @@ -function displayErrorMessage(errorMessage) { - const errorReport = document.querySelector("#errorReport"); - errorReport.innerHTML = JSON.parse(errorMessage).error; -} - function postToLoginEndpoint(event) { event.preventDefault(); @@ -10,9 +5,10 @@ function postToLoginEndpoint(event) { "username" : this.elements.username.value, "password" : this.elements.password.value } - const url = "https://reqres.in/api/login" // mock api service + const url = "https://" + window.location.hostname + ":8444/api/v1/account/login/"; const xhr = new XMLHttpRequest(); + console.log("Attempting a connection to the following endpoint: " + url); console.log("User credentials:\n" + JSON.stringify(credentials)); xhr.open("POST", url, true); @@ -22,14 +18,14 @@ function postToLoginEndpoint(event) { if (this.status === 200) { console.log("LOGIN SUCCESS!"); console.log("Server response:\n" + this.response); - token = JSON.parse(this.response).token; + token = JSON.parse(this.response).key; localStorage.setItem("token", token); window.location.replace("home.html"); } else { + document.getElementById("errorLogin").innerHTML = "Incorrect user name or password"; console.error("LOGIN FAILURE!"); console.error("Server status: " + this.status); console.error("Server response:\n" + this.response); - displayErrorMessage(this.response); } } }; diff --git a/front/static/js/logout.js b/front/static/js/logout.js index c10c381..b3bef0d 100644 --- a/front/static/js/logout.js +++ b/front/static/js/logout.js @@ -2,18 +2,18 @@ function postToLogoutEndpoint(event) { event.preventDefault(); const token = localStorage.getItem("token"); - const url = "https://reqres.in/api/logout" // mock api service + const url = "https://" + window.location.hostname + ":8444/api/v1/account/logout/"; const xhr = new XMLHttpRequest(); xhr.open("POST", url, true); - xhr.setRequestHeader("Authorization", "Token " + token); + xhr.setRequestHeader("Authorization", "Bearer " + token); xhr.onreadystatechange = function() { if (this.readyState === 4) { if (this.status === 200) { console.log("LOGOUT SUCCESS!"); console.log("Server response:\n" + this.response); localStorage.removeItem("token"); - window.location.replace("index.html"); + window.location.replace("/"); } else { console.error("LOGOUT FAILURE!"); console.error("Server status: " + this.status); diff --git a/front/static/js/viewHistory.js b/front/static/js/viewHistory.js index 7e7a88c..4b2899b 100644 --- a/front/static/js/viewHistory.js +++ b/front/static/js/viewHistory.js @@ -10,7 +10,9 @@ function getDataFromEndpoint(url, callback) { console.log("Attempting a connection to the following endpoint: " + url); + xhr.open("GET", url, true); + xhr.setRequestHeader("Authorization", "Bearer " + token); xhr.onreadystatechange = function() { if (this.readyState === 4) { if (this.status === 200) { @@ -222,7 +224,7 @@ function displayListOfReports(parsedData) { for (let i = 0; i < reports.length; i++) { let title = reports[i].title; let dateCreated = new Date(reports[i].date_created).toLocaleDateString("en-US"); - let state = reports[i].state; + let state = reports[i].submitted; let dateSubmitted; let rid = reports[i].report_pk; @@ -240,7 +242,7 @@ function displayListOfReports(parsedData) { actionButton.setAttribute("data-rid", rid); actionButton.classList.add("btn"); - if (state === "created") { + if (state === false) { // Edit button dateSubmitted = "TBD"; actionButton.classList.add("btn-primary", "edit-report-button"); // Add event listener class diff --git a/front/static/login.html b/front/static/login.html index 5c60531..9a8af2f 100644 --- a/front/static/login.html +++ b/front/static/login.html @@ -31,6 +31,7 @@ +

@@ -41,7 +42,6 @@ -