-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (52 loc) · 1.81 KB
/
index.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
// DARK MOOD
const blackThem = document.querySelector("#them-changer");
blackThem.addEventListener("click" , () => {
blackThem.classList.toggle('fa-sun');
if (blackThem.classList.contains('fa-sun')) {
const color = document.body
color.classList.add("active");
} else {
document.body.classList.remove('active');
}
})
// VALIDATION
const emailInput = document.querySelector(".email-input");
const passwordInput = document.querySelector(".pass-input");
const emailMsg = document.querySelector(".wrong-email");
const passwordMsg = document.querySelector(".wrong-pass");
const signinBtn = document.querySelector(".Signin-btn");
signinBtn.addEventListener("click" , signIn);
function signIn (event) {
event.preventDefault();
emailMsg.innerText ="";
passwordMsg.innerText = "";
const emailValue = emailInput.value;
const passwordValue = passwordInput.value;
let ifSendData = true
if (emailValue.length === 0 || emailValue.indexOf("@") === -1 || emailValue.indexOf(".") === -1) {
emailMsg.innerText = "Please enter a valid Email."
ifSendData = false;
}
if (passwordValue.length === 0) {
passwordMsg.innerText = "Please enter your password."
ifSendData = false;
} else if (passwordValue.length <= 4) {
passwordMsg.innerText = "Your password is too short."
ifSendData = false;
}
if (ifSendData) {
const body = JSON.stringify({
email:emailValue ,
password:passwordValue,
});
const headers = {
"Content-Type": "application/json"
};
fetch('https://jsonplaceholder.typicode.com/posts' , {
method:"POST",
body:body,
headers:headers
})
.then((response) => console.log(response))
}
}