-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (34 loc) · 1.45 KB
/
script.js
File metadata and controls
42 lines (34 loc) · 1.45 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
document.getElementById("loginForm").addEventListener("submit", function(event) {
event.preventDefault();
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
var userType = document.getElementById("userType").value;
// Basic email format validation
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
alert("Please enter a valid email address.");
return;
}
// Basic password length validation
if (password.length < 6) {
alert("Password must be at least 6 characters long.");
return;
}
// Simulating authentication
var users = {
"admin": { email: "admin@example.com", password: "admin123" },
"educator": { email: "educator@example.com", password: "educator123" },
"general": { email: "user@example.com", password: "user123" }
};
var user = users[userType];
if (!user || user.email !== email || user.password !== password) {
alert("Invalid email or password.");
return;
}
// If all validations pass, you can redirect the user or perform further actions
alert("Login successful. Redirecting...");
// For demonstration, let's redirect the user to a new page after 1 second
setTimeout(function() {
window.location.href = "dashboard.html"; // Redirect to dashboard page
}, 1000);
});