Add app
This commit is contained in:
125
templates/door.html
Normal file
125
templates/door.html
Normal file
@@ -0,0 +1,125 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Smart Door Lock</title>
|
||||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Arial', sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
#lockContainer {
|
||||
text-align: center;
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
#lockIcon {
|
||||
font-size: 60px;
|
||||
color: #3498db; /* Default color for locked icon */
|
||||
}
|
||||
|
||||
#idCardStatus {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
p.accessGranted {
|
||||
color: #2ecc71;
|
||||
}
|
||||
|
||||
p.accessDenied {
|
||||
color: #e74c3c;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="lockContainer">
|
||||
<div id="lockIcon">🔒</div>
|
||||
<div id="idCardStatus">
|
||||
<p>Waiting for card...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var requestInProgress = false;
|
||||
var currentUid = null;
|
||||
|
||||
const checkIdCardContents = async (sector, requiredContents) => {
|
||||
const data = await fetch("/api/sector/" + sector);
|
||||
const dump = (await data.json()).dump;
|
||||
console.log(dump === requiredContents);
|
||||
return dump === requiredContents;
|
||||
};
|
||||
|
||||
const checkIdCardStatus = () => {
|
||||
fetch("/api/uid").then(async (data) => {
|
||||
const uid = (await data.json()).uid;
|
||||
if (uid === currentUid) {
|
||||
setTimeout(checkIdCardStatus, 0);
|
||||
return;
|
||||
}
|
||||
currentUid = uid;
|
||||
if (uid) {
|
||||
const item = {{allowed_ids|tojson}}[uid];
|
||||
if (item === undefined) updateStatus("Access Denied - ID: " + uid, "accessDenied", "🔒"); // Change to locked icon
|
||||
else if (item[1].length > 0) {
|
||||
updateStatus("ID: " + uid, "", "🔒", "<b>Reading card, please wait...</b>");
|
||||
let contentsCorrect = true;
|
||||
for (let sectorInfo of item[1]) {
|
||||
if (!(await checkIdCardContents(...sectorInfo))) {
|
||||
contentsCorrect = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (contentsCorrect) {
|
||||
updateStatus("Unlocked - ID: " + uid, "accessGranted", "🔓", item[0] + "<br/></br><b>Card contents correct</b>");
|
||||
} else {
|
||||
updateStatus("Access Denied - ID: " + uid, "accessDenied", "🔒", "<b>Card contents incorrect</b>");
|
||||
}
|
||||
} else {
|
||||
updateStatus("Unlocked - ID: " + uid, "accessGranted", "🔓", item[0]);
|
||||
}
|
||||
} else {
|
||||
updateStatus("Waiting for card...", "", "🔒"); // No loading icon
|
||||
}
|
||||
|
||||
setTimeout(checkIdCardStatus, 0);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
updateStatus("Error occurred while checking ID card status.", "", "🔒"); // No loading icon
|
||||
setTimeout(checkIdCardStatus, 0);
|
||||
});
|
||||
}
|
||||
|
||||
const updateStatus = (status, className, icon, message = '') => {
|
||||
$("#idCardStatus").html("<p class='" + className + "'>" + status + "</p>");
|
||||
if (message != '') {
|
||||
$("#idCardStatus").append("<br/><p class='" + className + "'>" + message + "</p>");}
|
||||
$("#lockIcon").html(icon);
|
||||
};
|
||||
|
||||
// Initial check when the page loads
|
||||
checkIdCardStatus();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user