forked from aman1722/Industry-Buying-Clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign-in.js
36 lines (33 loc) · 1.14 KB
/
sign-in.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
let email = document.getElementById("email");
let password = document.getElementById("password");
let form = document.querySelector("form");
form.addEventListener("submit", async function(el){
el.preventDefault();
try {
if(email.value==="[email protected]" && password.value==="admin"){
alert("Welcome Admin!")
window.location.href="dashboard.html"
}else{
let req = await fetch("https://iris-conscious-potential.glitch.me/users");
let res = await req.json();
let user={};
let flag =false;
for(let i=0 ; i<res.length ; ++i){
if(email.value===res[i].email && password.value===res[i].password){
user = res[i];
flag = true;
}
}
if(flag){
localStorage.setItem("loggedINUser", JSON.stringify(user));
alert("login successful");
window.location.href="index.html";
}else{
alert("user not found");
}
}
}
catch (error) {
console.log(error);
}
})