-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (38 loc) · 1.27 KB
/
Copy pathscript.js
File metadata and controls
48 lines (38 loc) · 1.27 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
function signup() {
let name = document.getElementById("signupName").value;
let email = document.getElementById("signupEmail").value;
let password = document.getElementById("signupPassword").value;
if (name === "" || email === "" || password === "") {
alert("Please fill all fields");
return;
}
let user = {
name: name,
email: email,
password: password
};
localStorage.setItem(email, JSON.stringify(user));
alert("Signup successful!");
window.location.href = "login.html";
}
function login() {
let email = document.getElementById("loginEmail").value;
let password = document.getElementById("loginPassword").value;
let user = localStorage.getItem(email);
if (user === null) {
alert("User not found!");
return;
}
let data = JSON.parse(user);
if (data.password === password) {
localStorage.setItem("isLoggedIn", "true");
window.location.href = "dashboard.html"; // create this next
} else {
alert("Incorrect password!");
}
// After successful login
localStorage.setItem("isLoggedIn", "true");
localStorage.setItem("userEmail", email); // optional
// Redirect to dashboard
window.location.href = "dashboard.html";
}