-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
68 lines (46 loc) · 1.56 KB
/
home.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
64
65
66
let login = document.getElementById('log')
login.addEventListener('click',getInfoOfUsers)
let sign= document.getElementById('regis')
sign.addEventListener('click',storeInfo)
function storeInfo(){
var email = document.getElementById('email').value
var pass = document.getElementById('pass').value
var arr=[ email,pass]
console.log(email,pass)
console.log('hi')
event.preventDefault()
var data = localStorage.getItem("data")
var userdata = JSON.parse(data) || []
for(var i=0;i<userdata.length;i++){
if(userdata[i][0]==email){
alert("already registered")
return false
}
}
var inputuser = document.querySelectorAll('#exampleModal1>input')
for(var i=0;i<inputuser.length;i++){
if(inputuser[i].value==""){
alert("All fields are required")
return false
}
}
userdata.push(arr)
var str = JSON.stringify(userdata)
localStorage.setItem("data", str)
window.location = "home.html"
}
function getInfoOfUsers(){
var data = localStorage.getItem("data")
var userData = JSON.parse(data)
// console.log(userData)
event.preventDefault()
var email = document.getElementById('email1').value
var pass = document.getElementById('pass1').value
for(var i=0;i<userData.length;i++){
console.log("no")
if(email==userData[i][0] && pass==userData[i][1]){
//console.log(data[i][0])
window.location = "index.html"
}
}
}