-
Notifications
You must be signed in to change notification settings - Fork 4
/
login-signup.html
170 lines (147 loc) · 5.51 KB
/
login-signup.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html>
<head>
<title>Login and Signup</title>
<link rel="stylesheet" href="./CSS/login-signup.css">
</head>
<body>
<div class="container" id="main">
<div class="sign-up">
<form id="signupForm">
<h1>Create Account</h1>
<p>Use your email for registration</p>
<input type="text" name="txt" placeholder="Name" required id="signupNameInput">
<input type="email" name="email" placeholder="Email" required id="signupEmailInput">
<input type="password" name="pswd" placeholder="Password" required id="signupPassInput">
<input type="submit" class="button" value="SIGN UP"></input>
</form>
</div>
<!-- ----------------------------------------------------------------------->
<div class="sign-in">
<form id="loginForm" >
<h1>Sign in</h1>
<p>Please enter your Email and Password to Login</p>
<label>
User: <input type="radio" value="user" id="userCheck" class="checkBox" name="login" checked>
Admin:<input type="radio" value="admin" id="adminCheck" class="checkBox" name="login">
</label>
<input type="text" name="email" placeholder="Email" required id="loginEmailInput">
<input type="password" name="pswd" placeholder="Password" required id="loginPassInput">
<a href="#">Forget your Password?</a>
<input type="submit" class="button" value="SIGN IN"></input>
</form>
</div>
<!-- ----------------------------------------------------------------------->
<div class="overlay-container">
<div class="overlay">
<div class="overlay-left">
<h1>Welcome Back!</h1>
<p>Already have an account?
Click on the button below to login!
</p>
<button id="signIn">Sign In</button>
</div>
<div class="overlay-right">
<h1>Hello, Friend</h1>
<p>New to Travelist?<br>
Enter your personal details and start your journey with us</p>
<button id="signUp">Sign Up</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Fetch all users from API>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
let allUsers = [];
fetchUsers();
async function fetchUsers(){
try {
let res = await fetch("https://api-by-alisha-khan.onrender.com/users")
let data = await res.json();
console.log(data);
allUsers = data;
} catch (error) {
console.log(error);
}
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<0>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<--SLiding Animation-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//Do not touch this portion + + + + + + + +
const signUpButton = document.getElementById('signUp');
const signInButton = document.getElementById('signIn');
const main = document.getElementById('main');
signUpButton.addEventListener('click', () => {
main.classList.add("right-panel-active");
});
signInButton.addEventListener('click', () => {
main.classList.remove("right-panel-active");
});
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<0>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---Related to LOGIN/ SIGN IN--->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
let loginForm = document.querySelector("#loginForm");
let loginEmail = document.querySelector("#loginEmailInput");
let loginPass = document.querySelector("#loginPassInput");
let adminCheck = document.querySelector("#adminCheck");
let userCheck = document.querySelector("#userCheck")
//---ADMIN and User Login------>
loginForm.addEventListener("submit",function(e){
e.preventDefault();
if(adminCheck.checked){
if(loginEmail.value == "admin@masai.com" && loginPass.value == "saurabh") {
window.location.href = "dashboard.html";
localStorage.setItem("username", "admin@masaischool.com");
localStorage.setItem("password", "unicorn");
}
else{
alert("Enter correct Login Credentials!");
}
}
if(userCheck.checked){
let flag=false;
for(let el of allUsers){
if((el.gmail==loginEmail.value || el.name == loginEmail.value) && (el.password = loginPass.value)){
flag=true;
localStorage.setItem("userName", el.name);
localStorage.setItem("userPass", el.password);
window.location.href = "choice.html";
break;
}
}
console.log(flag);
alert((flag)?"Login Successful": "Please check you credentials!")
}
})
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<0>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---Related to SIGN UP--->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
let signupForm = document.querySelector("#signupForm");
let signupName = document.querySelector("#signupNameInput");
let signupEmail = document.querySelector("#signupEmailInput");
let signupPass = document.querySelector("#signupPassInput");
signupForm.addEventListener("submit",function(e){
e.preventDefault();
let obj={}
obj.name = signupName.value;
obj.gmail = signupEmail.value;
obj.password = signupPass.value;
addNewUser(obj);
})
async function addNewUser(obj) {
try {
let res = await fetch("https://api-by-alisha-khan.onrender.com/users",{
method:"POST",
body:JSON.stringify(obj),
headers:{
"Content-Type":"application/json"
}
})
let data = await res.json();
console.log(data);
fetchUsers();
} catch (error) {
console.log(error);
}
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<0>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
</script>
</body>
</html>