-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html.1
110 lines (110 loc) · 3.55 KB
/
index.html.1
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Log In</title>
</head>
<link
href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet"
/>
<body
class="font-sans text-lg text-gray-800 text-center"
style="background-color: #f3f3f3"
>
<center>
<div class="w-full max-w-xs m-4">
<form class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
<div class="mb-4">
<label
class="block text-gray-700 text-sm font-bold mb-2"
for="username"
>
E-mail
</label>
<input
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
id="email"
type="email"
placeholder="E-mail"
/>
</div>
<div class="mb-6">
<label
class="block text-gray-700 text-sm font-bold mb-2"
for="password"
>
Password
</label>
<input
class="shadow appearance-none border border-red-500 rounded w-full py-2 px-3 text-gray-700 mb-3 leading-tight focus:outline-none focus:shadow-outline"
id="password"
type="password"
placeholder="******************"
/>
<!-- <p class="text-red-500 text-xs italic">Please choose a password.</p> -->
</div>
<div class="flex items-center justify-between">
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline"
type="button"
id="submit"
>
Log In
</button>
<a
class="inline-block align-baseline font-bold text-sm text-blue-500 hover:text-blue-800"
href="/signup"
>
New user
</a>
</div>
</form>
</div>
</center>
</body>
<script>
const emailInput = document.querySelector("#email");
const passInput = document.querySelector("#password");
const submitBtn = document.querySelector("#submit");
const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
submitBtn.addEventListener("click", (event) => {
// checking for empty submission
if (!emailInput.value || !passInput.value) {
alert("Please Enter Valid Input");
return;
}
// checking length of password
if (passInput.value.length <= 5) {
alert("Password Minimum 6 charter");
return;
}
// validating email
if (!reg.test(emailInput.value.toLowerCase())) {
alert("Please Input A Valid Email");
return;
}
fetch("/api/v1/user/login", {
Accept: "application/json",
method: "POST",
"Content-Type": "application/json",
body: JSON.stringify({
email: emailInput.value,
password: passInput.value,
}),
})
.then((res) => res.json())
.then((res) => {
if (res.ok) {
// redirect to "/"
window.location = "/";
}
})
.catch((err) => {
alert("Something Went Wrong");
console.error(err);
});
});
</script>
</html>