-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (48 loc) · 2.26 KB
/
Copy pathscript.js
File metadata and controls
53 lines (48 loc) · 2.26 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
47
48
49
50
51
52
53
document.addEventListener("DOMContentLoaded", () => {
const emailInput = document.getElementById("email");
const passwordInput = document.getElementById("password");
const eyeIcon = document.getElementById("invisible");
const loginButton = document.getElementById("Login-btn");
// Toggle Password Visibility
if (eyeIcon && passwordInput) {
eyeIcon.addEventListener("click", () => {
const isPasswordHidden = passwordInput.type === "password";
passwordInput.type = isPasswordHidden ? "text" : "password";
eyeIcon.innerHTML = isPasswordHidden
? '<i class="fa-regular fa-eye"></i>'
: '<i class="fa-regular fa-eye-slash"></i>';
});
}
// Signup & Login Logic
if (loginButton && emailInput && passwordInput) {
loginButton.addEventListener("click", () => {
const email = emailInput.value.trim();
const password = passwordInput.value.trim();
if (!email || !password) {
alert("Please fill in all fields.");
return;
}
if (window.location.pathname.includes("signup")) {
try {
localStorage.setItem(email, password);
console.log("Stored Data:", localStorage.getItem(email)); // Debugging
alert("Signup successful! Redirecting to login...");
window.location.href = "login.html";
} catch (error) {
console.error("Error saving to localStorage:", error);
alert("Signup failed. Please try again.");
}
} else if (window.location.pathname.includes("login")) {
const storedPassword = localStorage.getItem(email);
console.log("Retrieved Password:", storedPassword); // Debugging
if (storedPassword && storedPassword === password) {
alert("Login successful! Redirecting to homepage...");
window.location.href = "index.html";
} else {
alert("Invalid email or password! Redirecting to signup...");
window.location.href = "signup.html";
}
}
});
}
});