-
Notifications
You must be signed in to change notification settings - Fork 0
/
login-script.js
63 lines (53 loc) · 1.96 KB
/
login-script.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
const form = document.getElementById("form");
let email = document.getElementById("emailbox");
let password = document.getElementById("password");
// let noName = document.getElementById("no-name");
let noEmail = document.getElementById("nomail");
let noPassword = document.getElementById("nopassword");
let wrongmail= document.getElementById("wrongmail");
let wrongpassword= document.getElementById("wrongpassword");
let hidden="hidden";
let invalidinfo="invalid-info";
let validinfo="valid-info";
form.addEventListener("submit", (e) => {
e.preventDefault();
noEmail.classList.add(hidden);
noPassword.classList.add(hidden);
wrongmail.classList.add(hidden);
wrongpassword.classList.add(hidden);
if (password.value==="") {
noPassword.classList.remove(hidden);
password.classList.add(invalidinfo);
// return;
}
if (email.value==="") {
noEmail.classList.remove(hidden);
email.classList.add(invalidinfo);
}
else if(password.value!=""){
email.classList.remove(invalidinfo);
email.classList.add(validinfo);
if (localStorage.getItem(email.value)==null) {
wrongmail.classList.remove(hidden);
// noPassword.classList.add(hidden);
password.classList.remove(invalidinfo);
}
else{
let data=JSON.parse(localStorage.getItem(email.value));
console.log(data);console.log(password.value);
if(data.password!=password.value){
wrongpassword.classList.remove(hidden);
password.classList.add(invalidinfo);
}
else{
password.classList.remove(invalidinfo);
password.classList.add(validinfo);
location.href="website.html";
}
}
}
else{
email.classList.remove(invalidinfo);
email.classList.add(validinfo);
}
})