forked from nikhila-kuchimanchi/oratory_coach_results
-
Notifications
You must be signed in to change notification settings - Fork 8
/
auth.js
65 lines (56 loc) · 2.12 KB
/
auth.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Users data (to simulate a real backend)
const users = [
{ email: "[email protected]", password: "password123" },
{ email: "[email protected]", password: "adminpass" },
{ email: "[email protected]", password: "userpass" }
];
// Login form event listener
document.getElementById("loginForm").onsubmit = function(event) {
event.preventDefault();
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
const emailError = document.getElementById("emailError");
const passwordError = document.getElementById("passwordError");
const loading = document.getElementById("loading");
// Reset errors
emailError.textContent = "";
passwordError.textContent = "";
// Simple email validation
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
emailError.textContent = "Invalid email format.";
return;
}
// Check password length
if (password.length < 8) {
passwordError.textContent = "Password must be at least 8 characters long.";
return;
}
// Simulate backend login (fake authentication)
const user = users.find(user => user.email === email && user.password === password);
if (user) {
// Show loading animation (simulated login process)
loading.style.display = "block";
// Redirect after short delay to simulate processing
setTimeout(() => {
window.location.href = "index.html";
}, 1500);
} else {
passwordError.textContent = "Invalid email or password.";
}
};
// Show/Hide password functionality
document.getElementById("togglePassword").onclick = function() {
const passwordInput = document.getElementById("password");
if (passwordInput.type === "password") {
passwordInput.type = "text";
this.textContent = "Hide";
} else {
passwordInput.type = "password";
this.textContent = "Show";
}
};
// Forgot password alert (temporary)
document.getElementById("forgotPassword").onclick = function() {
alert("Password recovery options coming soon!");
};