diff --git a/html/index.html b/html/index.html
index 7a7dbef..293cd53 100644
--- a/html/index.html
+++ b/html/index.html
@@ -11,7 +11,6 @@
-
diff --git a/html/js/login.js b/html/js/login.js
new file mode 100644
index 0000000..57658e5
--- /dev/null
+++ b/html/js/login.js
@@ -0,0 +1,17 @@
+// Retrieve username and password from fields, store a token, and redirect to main app
+function processLogin() {
+ var username = $("#loginName").val();
+ var password = $("#loginPassword").val();
+ window.localStorage.setItem("authtoken", btoa(username + ":" + password));
+ window.location.replace(jsconfig.baseurl + "/app/");
+};
+
+function addClickToLogin() {
+ $("#loginButton").click(processLogin);
+};
+
+// If the login page is displayed, we need to remvoe any existing auth tokens
+window.localStorage.removeItem("authtoken");
+
+// Set the click function for the login button
+$(document).ready(addClickToLogin);
diff --git a/html/js/thermostat.js b/html/js/thermostat.js
index 2be281d..6ad7f7f 100644
--- a/html/js/thermostat.js
+++ b/html/js/thermostat.js
@@ -1,6 +1,7 @@
// Set the auth header if necessary
function authHeaders(xhr) {
if (window.localStorage.getItem("authtoken") !== null) {
+ var authToken = window.localStorage.getItem("authtoken");
xhr.setRequestHeader("Authorization", "Basic " + authToken);
}
}
@@ -24,6 +25,19 @@ function redirectIfNotAuthorized() {
// Call the redirect function
redirectIfNotAuthorized();
+// Display version at bottom of page
+function renderVersion() {
+ $.ajax({
+ url: jsconfig.baseurl + "/api/version",
+ beforeSend: authHeaders
+ }).then(function(data) {
+ var versionText = "TempGopher © 2018 Mike Shoup | Version: " + data.version;
+ $("#version").text(versionText);
+ });
+};
+$(document).ready(renderVersion);
+
+
function celsiusToFahrenheit(degree) {
return degree * 1.8 + 32;
}
diff --git a/html/js/version.js b/html/js/version.js
deleted file mode 100644
index 0c7d462..0000000
--- a/html/js/version.js
+++ /dev/null
@@ -1,9 +0,0 @@
-function renderVersion() {
- $.ajax({
- url: jsconfig.baseurl + "/api/version"
- }).then(function(data) {
- var versionText = "TempGopher © 2018 Mike Shoup | Version: " + data.version;
- $("#version").text(versionText);
- });
-};
-$(document).ready(renderVersion);
diff --git a/html/login.html b/html/login.html
index 377f442..52ab9da 100644
--- a/html/login.html
+++ b/html/login.html
@@ -10,7 +10,7 @@
-
+
-
-