-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (74 loc) · 3.51 KB
/
Copy pathindex.js
File metadata and controls
93 lines (74 loc) · 3.51 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
document.addEventListener('DOMContentLoaded', () => {
const themeSwitch = document.getElementById('theme-switch');
const passwordForm = document.getElementById('passform');
const tableBody = document.getElementById('tableBody');
const noPasswordsSection = document.getElementById('no-passwords');
const passwordToggle = document.querySelector('.toggle-password');
const passwordInput = document.getElementById('password');
const signupBtn = document.getElementById('signup-btn');
const signupSection = document.getElementById('signup-section');
const signupForm = document.getElementById('signupform');
const loginForm = document.getElementById('loginform');
const initTheme = () => {
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', savedTheme);
themeSwitch.checked = savedTheme === 'dark';
};
initTheme();
themeSwitch.addEventListener('change', () => {
const theme = themeSwitch.checked ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
});
const icon = document.getElementById("icon");
const featurePanel = document.getElementById("featurepanel");
icon.addEventListener("mouseenter", () => {
featurePanel.classList.add("show");
});
featurePanel.addEventListener("mouseleave", () => {
featurePanel.classList.remove("show");
});
signupBtn.addEventListener('click', () => {
signupSection.style.display =
signupSection.style.display === 'none' ? 'block' : 'none';
});
//User signup form submission in localStorage
signupForm.addEventListener('submit', (e) => {
e.preventDefault();
const username = signupForm.querySelector('#signup-username').value;
const email = signupForm.querySelector('#signup-email').value.trim();
const password = signupForm.querySelector('#signup-password').value.trim();
const confirmPassword= signupForm.querySelector('#signup-confirm-password').value.trim();
if (password !== confirmPassword) {
alert('Passwords do not match');
return;
}
const users = JSON.parse(localStorage.getItem('users') || '[]');
if (users.some(user => user.email === email)) {
alert('User already exists');
return;
}
users.push({ username, email, password, passwords: [] });
localStorage.setItem('users',JSON.stringify(users));
alert('Signup successful');
signupForm.reset();
});
//User Login
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = loginForm.querySelector('#email-input').value.trim();
const password = loginForm.querySelector('#password-input').value.trim();
console.log('Entered Email:', email);
console.log('Entered Password', password);
const users = JSON.parse(localStorage.getItem('users') || '[]');
console.log('Stored Users:', users);
const user = users.find(u => u.email === email && u.password === password);
if (user) {
sessionStorage.setItem('currentUser', JSON.stringify(user));
window.location.href = 'pass-org.html';
} else {
alert('Invalid email or password');
}
loginForm.reset();
});
});