mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 08:39:43 +00:00
Added login ability
This commit is contained in:
parent
dd3e78eb28
commit
5fd5acc0cc
5 changed files with 33 additions and 17 deletions
|
|
@ -11,7 +11,6 @@
|
||||||
<script src="js/jquery.min.js"></script>
|
<script src="js/jquery.min.js"></script>
|
||||||
<script src="/jsconfig.js"></script>
|
<script src="/jsconfig.js"></script>
|
||||||
<script src="js/thermostat.js"></script>
|
<script src="js/thermostat.js"></script>
|
||||||
<script src="js/version.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
|
||||||
17
html/js/login.js
Normal file
17
html/js/login.js
Normal file
|
|
@ -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);
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Set the auth header if necessary
|
// Set the auth header if necessary
|
||||||
function authHeaders(xhr) {
|
function authHeaders(xhr) {
|
||||||
if (window.localStorage.getItem("authtoken") !== null) {
|
if (window.localStorage.getItem("authtoken") !== null) {
|
||||||
|
var authToken = window.localStorage.getItem("authtoken");
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + authToken);
|
xhr.setRequestHeader("Authorization", "Basic " + authToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,6 +25,19 @@ function redirectIfNotAuthorized() {
|
||||||
// Call the redirect function
|
// Call the redirect function
|
||||||
redirectIfNotAuthorized();
|
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) {
|
function celsiusToFahrenheit(degree) {
|
||||||
return degree * 1.8 + 32;
|
return degree * 1.8 + 32;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<link rel="icon" type="image/png" href="img/favicon.png">
|
<link rel="icon" type="image/png" href="img/favicon.png">
|
||||||
<script src="js/jquery.min.js"></script>
|
<script src="js/jquery.min.js"></script>
|
||||||
<script src="/jsconfig.js"></script>
|
<script src="/jsconfig.js"></script>
|
||||||
<script src="js/version.js"></script>
|
<script src="js/login.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
@ -28,12 +28,7 @@
|
||||||
<div class="four columns"><input type="password" style="width: 100%" id="loginPassword" /></div>
|
<div class="four columns"><input type="password" style="width: 100%" id="loginPassword" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="four columns offset-by-four"><button type="submit" style="width: 100%" class="button button-primary">Login</button></div>
|
<div class="four columns offset-by-four"><button type="submit" id="loginButton" style="width: 100%" class="button button-primary">Login</button></div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="container">
|
|
||||||
<div class="row" style="margin-top: 10rem">
|
|
||||||
<h6 id="version"></h6>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue