-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
195 lines (179 loc) · 7.31 KB
/
index.html
File metadata and controls
195 lines (179 loc) · 7.31 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign In</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
.container {
text-align: center;
background-color: #ffffff;
padding: 50px;
width: 20%;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
h1 {
margin-bottom: 20px;
color: #333;
}
input[type="email"], input[type="password"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: none;
border-radius: 8px;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
font-size: 16px;
}
button {
background-color: #000;
color: #fff;
padding: 10px 20px;
margin: 10px;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
transition: background-color 0.3s;
}
button:hover {
background-color: #333;
}
label {
display: block;
margin-bottom: 5px;
font-size: 16px;
color: #333;
}
</style>
</head>
<body>
<div class="container">
<h1>COMICS <span style="color: red;">TV</span></h1>
<form id="signInForm" novalidate>
<div class="input-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="input-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<div>
<button type="button" id="signupButton">Signup</button>
<button type="button" id="loginButton">Login</button>
</div>
</form>
<div class="message" id="message"></div>
</div>
<script type="module">
// Import necessary Firebase SDKs
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.0.1/firebase-app.js";
import { getAuth, signInWithEmailAndPassword, createUserWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/11.0.1/firebase-auth.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/11.0.1/firebase-analytics.js";
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyCN8UQscHAfxsKfn6tJ5yHtAj00EG3V8zI",
authDomain: "comics-tv-8e695.firebaseapp.com",
projectId: "comics-tv-8e695",
storageBucket: "comics-tv-8e695.appspot.com",
messagingSenderId: "457088220613",
appId: "1:457088220613:web:529c86c12d13435f6adfac",
measurementId: "G-CBWWFMVLKQ"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const auth = getAuth(app);
// DOM elements
const signInForm = document.getElementById('signInForm');
const messageDiv = document.getElementById('message');
const loginButton = document.getElementById('loginButton');
const signupButton = document.getElementById('signupButton');
// Additional error elements
const emailInput = signInForm.email;
const passwordInput = signInForm.password;
const emailError = document.createElement('div');
const passwordError = document.createElement('div');
emailError.style.color = 'red';
passwordError.style.color = 'red';
emailInput.parentNode.appendChild(emailError);
passwordInput.parentNode.appendChild(passwordError);
// Validate fields before action
function validateFields() {
const email = emailInput.value.trim();
const password = passwordInput.value.trim();
let isValid = true;
// Clear previous error messages
emailError.textContent = '';
passwordError.textContent = '';
messageDiv.textContent = '';
// Email validation
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!email) {
emailError.textContent = "Email is required.";
isValid = false;
} else if (!emailPattern.test(email)) {
emailError.textContent = "Please enter a valid email address.";
isValid = false;
}
if (password.length > 30) {
// Display the message
passwordError.textContent = "Password is too long. Maximum length is 30 characters.";
passwordError.style.display = 'block'; // Ensure the message is visible
return false; // Prevent form submission
} else {
// Hide the message if the password is valid
passwordError.style.display = 'none';
return true;
}
// Password validation
if (password === "")
{ passwordError.textContent = "Password is required!"; valid = false; }
else if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$/.test(password))
{ passwordError.textContent = "Password must be at least 8 characters long, contain an uppercase letter, a lowercase letter, a number, and a special character."; valid = false; }
return isValid;
}
// Handle sign-in
loginButton.addEventListener('click', async (e) => {
e.preventDefault();
if (!validateFields()) return;
const email = emailInput.value;
const password = passwordInput.value;
try {
const userCredential = await signInWithEmailAndPassword(auth, email, password);
const user = userCredential.user;
messageDiv.innerHTML = `<p style="color: green;">Welcome back, ${user.email}!</p>`;
window.location.href = "./assets/Home.html"; // Redirect to homepage or dashboard
} catch (error) {
messageDiv.innerHTML = `<p style="color: red;">Error: ${error.message}</p>`;
}
});
// Handle sign-up
signupButton.addEventListener('click', async (e) => {
e.preventDefault();
if (!validateFields()) return;
const email = emailInput.value;
const password = passwordInput.value;
try {
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
const user = userCredential.user;
messageDiv.innerHTML = `<p style="color: green;">Account created for ${user.email}!</p>`;
} catch (error) {
messageDiv.innerHTML = `<p style="color: red;">Error: ${error.message}</p>`;
}
});
</script>
</body>
</html>