-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
30 lines (25 loc) · 964 Bytes
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const dashboardURL = "pages/dashboard.html";
document.getElementById('loginForm').addEventListener('submit', async function(event) {
event.preventDefault();
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
try {
var response = await fetch('./Data/userinfo.json');
if (!response.ok) {
throw new Error('Failed to load user data');
}
var users = await response.json();
var authenticatedUser = users.find(function(user) {
return user.username === username && user.password === password;
});
if (authenticatedUser) {
window.sessionStorage.setItem("username", authenticatedUser.username);
window.location.href = dashboardURL;
} else {
document.getElementById('error').textContent = 'Invalid username or password';
}
} catch (error) {
console.error('Error:', error.message);
document.getElementById('error').textContent = 'Failed to load user data';
}
});