-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (40 loc) · 1.32 KB
/
script.js
File metadata and controls
46 lines (40 loc) · 1.32 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const usersTable = [
// Note: This is a fake table for educational purposes. Never store user credentials in plain text.
{ id: 1, username: "hello@world.com", password: "badpassword" },
{ id: 2, username: "test@user.com", password: "badpassword" },
{ id: 3, username: "email@domain.com", password: "badpassword" },
];
let renderSuccess = () => {
document.getElementById("success-message").hidden = false;
};
let renderError = () => {
document.getElementById("error-message").hidden = false;
};
let resetMessage = () => {
document.getElementById("success-message").hidden = true;
document.getElementById("error-message").hidden = true;
};
addEventListener("submit", (event) => {
event.preventDefault();
resetMessage();
let email = document.getElementById("email").value;
let password = document.getElementById("password").value;
console.log(`email submitted: ${email}`);
console.log(`password submitted: ${password}`);
const validUser = usersTable.some((user) => {
if (user.username === email && user.password === password) {
return true;
}
})
if (validUser) {
renderSuccess();
} else {
renderError();
}
/*
TODO:
1. Check if the email and password are valid (using the usersTable)
2. If they are, call renderSuccess()
3. If they are not, call renderError()
*/
});