initial commit

This commit is contained in:
Sergey Svinolobov
2024-06-24 16:02:24 -04:00
parent eea090518d
commit 2ccb8f55fe
10 changed files with 681 additions and 1 deletions

42
auth.js Normal file
View File

@@ -0,0 +1,42 @@
let authCredentials = { username: '', password: '' };
async function authenticateUser(username, password) {
const response = await fetch('auth.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
});
const result = await response.json();
return result.authenticated;
}
function checkAuthentication() {
if (authCredentials.username && authCredentials.password) {
document.getElementById('loginForm').style.display = 'none';
document.getElementById('uploadForm').style.display = 'block';
loadFileList();
} else {
document.getElementById('loginForm').style.display = 'block';
document.getElementById('uploadForm').style.display = 'none';
}
}
document.getElementById('authForm').addEventListener('submit', async function(event) {
event.preventDefault();
const username = document.getElementById('loginUsername').value;
const password = document.getElementById('loginPassword').value;
const isAuthenticated = await authenticateUser(username, password);
if (isAuthenticated) {
authCredentials = { username, password };
checkAuthentication();
} else {
document.getElementById('statusMessage').innerHTML = 'Incorrect username or password!';
}
});
document.addEventListener('DOMContentLoaded', checkAuthentication);