-
Notifications
You must be signed in to change notification settings - Fork 0
/
myAccount.js
70 lines (63 loc) · 2.26 KB
/
myAccount.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
let accountData = JSON.parse(localStorage.getItem("accountDatas")) || []
let account = document.querySelector("#createAccount")
let accounts = document.querySelector("#login")
document.querySelector("#createAccount").addEventListener("submit", createAccountFun);
document.querySelector("#login").addEventListener("submit", loginFun);
function createAccountFun(event) {
event.preventDefault();
let userFName = account.fname.value;
let userLName = account.lname.value;
let userMail = account.email.value;
let userPwd = account.pwd.value;
console.log(userPwd)
let userCPwd = account.cpwd.value;
let userChecked = account.checkBox.checked;
let userData = {
fname: userFName,
lname: userLName,
mail: userMail,
pwd: userPwd,
cpwd: userCPwd
}
if (userFName != "" && userLName != "" && userMail != "" && userPwd != "" && userCPwd != "" && userChecked != false) {
let filtered = accountData.filter(function (ele) {
return ele.mail == userMail;
})
if (userCPwd != userPwd) {
alert("Please Check Confirm Password is not Matched");
}
else if (filtered.length > 0) {
alert("Allready registered")
}
else {
alert("Thanks for Beliving on us. Please fill the adress for Better Experience")
accountData.push(userData)
localStorage.setItem("accountDatas", JSON.stringify(accountData));
window.location.href = "Address.html"
}
}
else {
alert("Invalid Credentials")
}
}
function loginFun(event) {
event.preventDefault();
let userMail = accounts.logemail.value;
let userPwd = accounts.logpwd.value;
let filtered = accountData.filter(function (ele) {
return ele.mail == userMail;
})
if (filtered.length > 0) {
if (filtered[0].pwd != userPwd) {
alert("Invalid password")
}
else {
alert("Logged in sucessfully")
localStorage.setItem("userDet",JSON.stringify(accountData))
window.location.href = "index.html"
}
}
else {
alert("User not found")
}
}