-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
76 lines (56 loc) · 1.64 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
// signup code
var arr = JSON.parse(localStorage.getItem("userDetails")) || []
var btn=document.getElementById('signbtn')
btn.addEventListener('click',myfunc)
function myfunc(event){
event.preventDefault();
userDetails = null
var obj = {
Ms:Ms.value,
Mrs:Mrs.value,
Mr:Mr.value,
select:select.value,
firstname:firstname.value,
lastname:lastname.value,
email:email.value,
password:password.value,
}
arr.push(obj)
// console.log(arr)
localStorage.setItem("userDetails",JSON.stringify(arr))
window.location.reload()
}
// login code
var user = JSON.parse(localStorage.getItem("userDetails")) || []
// console.log(user)
var bttn = document.getElementById('loginbtn')
bttn.addEventListener("click", func)
function func(){
event.preventDefault()
var userdata = {
user_email:user_email.value,
user_password:user_password.value
}
// console.log(userdata)
var exist = user.findIndex(function(ele){
return userdata.user_email == ele.email
// console.log(userdata.user_email)
})
console.log(exist)
flag = false;
if(exist==-1){
alert('Create account please')
}else{
user.findIndex(function(ele){
if(userdata.user_email===ele.email && userdata.user_password === ele.password){
alert("Account login Successfull")
flag=true;
localStorage.setItem("userdata",JSON.stringify(ele))
window.location.href="../index.html"
}
})
if(!flag){
alert("Login ceredential wrong!!")
}
}
}