forked from Wasim901/CW_Project393
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign.js
103 lines (79 loc) · 3.14 KB
/
sign.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
98
99
100
101
102
const forms = document.querySelector(".forms"),
pwShowHide = document.querySelectorAll(".eye-icon"),
links = document.querySelectorAll(".link");
pwShowHide.forEach(eyeIcon => {
eyeIcon.addEventListener("click", () => {
let pwFields = eyeIcon.parentElement.parentElement.querySelectorAll(".password");
pwFields.forEach(password => {
if(password.type === "password"){
password.type = "text";
eyeIcon.classList.replace("bx-hide", "bx-show");
return;
}
password.type = "password";
eyeIcon.classList.replace("bx-show", "bx-hide");
})
})
})
links.forEach(link => {
link.addEventListener("click", e => {
e.preventDefault(); //preventing form submit
forms.classList.toggle("show-signup");
})
})
// Get the signup form and login form elements
const signupForm = document.querySelector('.signup form');
const loginForm = document.querySelector('.login form');
// Add event listener to the signup form submit button
signupForm.addEventListener('submit', (e) => {
e.preventDefault();
// Get the user's email and password
const email = signupForm.querySelector('input[type="email"]').value;
const password = signupForm.querySelector('input[type="password"]').value;
// Check if the user's email already exists in local storage
let users = JSON.parse(localStorage.getItem('users')) || [];
const userExists = users.find(user => user.email === email);
if (userExists) {
// alert('User already exists!');
Swal.fire("Oops!", "User already exits!", "error")
}else{
users.push({email, password});
localStorage.setItem('users', JSON.stringify(users));
// Reset the form fields
signupForm.reset();
// alert('Signup successful!');
Swal.fire("Signup succesfull!", "Click on login", "success")
}
// Add the user's details to the users array and store it in local storage
});
// Add event listener to the login form submit button
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
// Get the user's email and password
const email = loginForm.querySelector('input[type="email"]').value;
const password = loginForm.querySelector('input[type="password"]').value;
// Check if the user's email and password match with any user in local storage
let users = JSON.parse(localStorage.getItem('users')) || [];
const user = users.find(user => user.email === email && user.password === password);
if (!user) {
Swal.fire(
'Oops Wrong Email & Password!',
'Something went wrong!',
'error'
)
}else{
loginForm.reset();
Swal.fire("Login successfully!", "Welcome to Oestin", "success")
myFunction();
}
// Reset the form fields
function myFunction() {
setTimeout(() => {
document.body.style.opacity = 0;
window.location.href = "hotel2.html";
}, 1000);
setTimeout(() => {
document.body.style.opacity = 1;
}, 2000);
}
});