-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (39 loc) · 1.34 KB
/
index.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
let data = JSON.parse(localStorage.getItem("user")) || []
console.log(data)
window.addEventListener("DOMContentLoaded", ()=>{
let handleLogin = document.getElementById("handleLogin")
handleLogin.addEventListener("click", login)
let signupBtn = document.getElementById("signupBtn")
signupBtn.addEventListener("click", signUp)
})
function login(){
let emailLogin = document.getElementById("emailLogin").value
let passwordLogin = document.getElementById("passwordLogin").value
let flag =false
for(let i=0;i<data.length;i++){
if(emailLogin==data[i].email && passwordLogin==data[i].password){
flag= true
localStorage.setItem("activeUser", JSON.stringify(emailLogin))
}
}
if(flag){
window.location.href= "dashboard.html"
}
else{
alert("wrong credential")
}
}
function signUp(){
let fnameSignup = document.getElementById("fnameSignup").value
let emailSignup = document.getElementById("emailSignup").value
let passwordSignup = document.getElementById("passwordSignup").value
let payload = {
fname: fnameSignup,
email: emailSignup,
password: passwordSignup
}
data.push(payload)
localStorage.setItem("user", JSON.stringify(data))
alert("Sign Up Successful")
window.location.href = "index.html"
}