-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsign_in_sign_up.js
97 lines (87 loc) · 2.54 KB
/
sign_in_sign_up.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
document.querySelector("#signupForm").addEventListener("submit",signUpFun);
document.querySelector("#signinPage").addEventListener("submit",signInFun);
function indexfun(){
console.log("abc")
window.location.href="index.html"
}
let userArr=JSON.parse(localStorage.getItem("userDataKey"))||[];
function signUpFun(event){
event.preventDefault();
let userData={
title:document.querySelector("#userTilte").value,
acTitle:document.querySelector("#userAcTitle").value,
name1:document.querySelector("#signupName1").value,
name2:document.querySelector("#signupName2").value,
email:document.querySelector("#signupEmail").value,
pass1:document.querySelector("#password1").value,
pass2:document.querySelector("#password2").value,
}
if(checkEmails(userData.email)==true && checkPassword(userData.pass1,userData.pass2)==true){
userArr.push(userData);
localStorage.setItem("userDataKey",JSON.stringify(userArr));
alert("Sign Up Successfully")
console.log(userArr)
}
else if(checkEmails(userData.email)==false && checkPassword(userData.pass1,userData.pass2)==true){
alert("Account has already been created")
}
else if(checkEmails(userData.email)==true && checkPassword(userData.pass1,userData.pass2)==false){
alert("Password Mismatched!")
}
}
function checkEmails(email){
var filtered=userArr.filter(function(element){
return email === element.email;
})
if(filtered.length>0){
return false;
}
else{
return true;
}
}
function checkPassword(pass1,pass2){
let count=0
for(let i=0,j=0;i<pass1.length,j<pass2.length;i++,j++){
if (pass1[i]==pass2[j]){
count++
}
else{
break;
}
}
if(count==pass1.length&&count==pass2.length){
return true;
}
else{
return false
}
}
// sign in
function signInFun(event){
event.preventDefault();
console.log("sign in")
let data={
email:document.querySelector("#siginEmail").value,
password:document.querySelector("#siginPassword").value
}
if (checksignindata(data.email,data.password)==true){
localStorage.setItem("siginKey",JSON.stringify(data))
alert("You have been logged in")
window.location.href="index.html"
}
else{
alert("Wrong Email/Password")
}
}
function checksignindata(email,password){
let filetr=userArr.filter(function(element){
return element.email===email && element.pass1===password;
})
if(filetr.length>0){
return true;
}
else{
return false
}
}