-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
586 lines (525 loc) · 28.8 KB
/
index.html
File metadata and controls
586 lines (525 loc) · 28.8 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ghatpar - Online Grocery Store</title>
<!-- Bootstrap & Animate.css -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<!-- Custom Styles -->
<style>
body {
background-image: url('image/LandingG.png'); /* Ensure this path is correct */
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
margin: 0;
padding: 0;
}
header {
background-color: #ffffff;
z-index: 1000;
}
.hero-section {
padding: 5rem 1rem;
text-align: center;
padding-top: 100px;
margin-top: 100px;
}
.hero-section i {
display: block;
margin-bottom: 0.5rem;
}
.popup-message {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #ffffff;
color: #333;
padding: 12px 24px;
border-radius: 6px;
z-index: 1050;
font-weight: bold;
display: none;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
transition: opacity 0.3s ease, transform 0.3s ease;
}
.popup-message.show {
display: block;
animation: slideDown 0.5s ease-out;
}
.popup-message.hide {
animation: fadeOutUp 0.5s ease-in forwards;
}
@keyframes slideDown {
from { opacity: 0; transform: translate(-50%, -40px); }
to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes fadeOutUp {
from { opacity: 1; transform: translate(-50%, 0); }
to { opacity: 0; transform: translate(-50%, -40px); }
}
</style>
</head>
<body>
<!-- Header -->
<header class="py-1 shadow">
<div class="container position-relative">
<nav class="navbar navbar-expand-lg">
<a class="navbar-brand text-dark fw-bold position-absolute start-50 translate-middle-x" href="index.html">Ghatpar.com</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<button class="btn btn-outline-primary me-2" data-bs-toggle="modal" data-bs-target="#authModal">Login</button>
</div>
</nav>
</div>
</header>
<!-- Hero Section -->
<section class="hero-section" style="background-color: transparent;">
<div class="container">
<h2 class="text-dark fw-bold mb-3">Groceries at Your Door in 30 Minutes!</h2>
<p class="text-muted mb-4">Fresh, fast, and reliable delivery—right from your neighborhood store.</p>
<div class="row justify-content-center mb-4">
<div class="col-md-2 col-6 mb-3"><i class="fas fa-clock fa-2x text-success"></i><p class="fw-bold mb-0">30 Min Delivery</p></div>
<div class="col-md-2 col-6 mb-3"><i class="fas fa-carrot fa-2x text-success"></i><p class="fw-bold mb-0">Fresh Items</p></div>
<div class="col-md-2 col-6 mb-3"><i class="fas fa-shield-alt fa-2x text-success"></i><p class="fw-bold mb-0">Secure Payment</p></div>
<div class="col-md-2 col-6 mb-3"><i class="fas fa-store fa-2x text-success"></i><p class="fw-bold mb-0">Local Sourcing</p></div>
<div class="col-md-2 col-6 mb-3"><i class="fas fa-thumbs-up fa-2x text-success"></i><p class="fw-bold mb-0">Quality Guaranteed</p></div>
</div>
<div class="d-flex justify-content-center mt-4">
<button class="btn btn-primary btn-lg d-flex align-items-center justify-content-center" data-bs-toggle="modal" data-bs-target="#authModal" style="gap: 10px;">
<img src="image/cartw.png" alt="Shopping Cart" style="max-width: 60px; height: auto;">
Start Shopping
</button>
</div>
<p class="text-muted mt-2">Join thousands of happy customers!</p>
</div>
</section>
<!-- Popup Message -->
<div id="popupMessage" class="popup-message"></div>
<!-- Auth Modal -->
<div class="modal fade" id="authModal" tabindex="-1" aria-labelledby="authModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="authModalTitle">Login</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<!-- Login Form -->
<div id="loginForm">
<form id="loginFormElement">
<div class="mb-3">
<input type="email" class="form-control" id="loginEmail" placeholder="Email" required />
</div>
<div class="mb-3">
<input type="password" class="form-control" id="loginPassword" placeholder="Password" required />
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="rememberMe" />
<label class="form-check-label" for="rememberMe">Remember Me</label>
</div>
<button type="submit" class="btn btn-primary w-100" data-original-text="Login">Login</button>
</form>
<div class="text-center mt-3">
<a href="#!" onclick="showForm('signupForm')">Create an Account</a><br />
<a href="#!" onclick="showForm('forgotForm')">Forgot Password?</a>
</div>
</div>
<!-- Signup Form -->
<div id="signupForm" class="d-none" aria-live="polite" aria-atomic="true">
<form id="signupFormElement" novalidate>
<div class="mb-3">
<label for="fullname" class="form-label text-dark fw-bold"><i class="fas fa-user"></i> Full Name</label>
<input type="text" class="form-control shadow-sm border-success" id="fullname" aria-describedby="fullnameError" required />
<div id="fullnameError" class="form-text text-danger visually-hidden"></div>
</div>
<div class="mb-3">
<label for="signupEmail" class="form-label text-dark fw-bold"><i class="fas fa-envelope"></i> Email</label>
<input type="email" class="form-control shadow-sm border-success" id="signupEmail" aria-describedby="emailError" required />
<div id="emailError" class="form-text text-danger visually-hidden"></div>
</div>
<div class="mb-3">
<label for="number" class="form-label text-dark fw-bold"><i class="fas fa-phone"></i> Phone Number</label>
<div class="input-group shadow-sm">
<select class="form-select border-success" style="max-width: 150px;" aria-label="Country code" id="countryCode">
<option value="+1" selected>+1 (US)</option>
<option value="+91">+91 (IN)</option>
<option value="+44">+44 (UK)</option>
<option value="+61">+61 (AU)</option>
<option value="+880" selected>+880 (BD)</option> {/* Default to BD */}
</select>
<input type="tel" class="form-control border-success" id="number" placeholder="Enter your phone number" aria-describedby="phoneError" required />
</div>
<div id="phoneError" class="form-text text-danger visually-hidden"></div>
</div>
<div class="mb-3 position-relative">
<label for="password" class="form-label text-dark fw-bold"><i class="fas fa-lock"></i> Password</label>
<div class="input-group">
<input type="password" class="form-control shadow-sm border-dark" id="password" aria-describedby="passwordError" required />
<button type="button" class="btn btn-outline-secondary" id="togglePassword" aria-label="Toggle password visibility"><i class="fas fa-eye"></i></button>
</div>
<div id="passwordError" class="form-text text-danger visually-hidden"></div>
</div>
<div class="mb-3 position-relative">
<label for="confirmPassword" class="form-label text-dark fw-bold"><i class="fas fa-lock"></i> Confirm Password</label>
<div class="input-group">
<input type="password" class="form-control shadow-sm border-dark" id="confirmPassword" aria-describedby="confirmPasswordError passwordMatchWarning" required />
<button type="button" class="btn btn-outline-secondary" id="toggleConfirmPassword" aria-label="Toggle confirm password visibility"><i class="fas fa-eye"></i></button>
</div>
<div id="passwordMatchWarning" class="text-danger small mt-1 visually-hidden" role="alert">Passwords do not match</div>
<div id="confirmPasswordError" class="form-text text-danger visually-hidden"></div>
</div>
<button type="submit" class="btn btn-primary w-100" data-original-text="Sign Up">Sign Up</button>
</form>
<div class="text-center mt-3">Already have an account? <a href="#!" onclick="showForm('loginForm')">Login</a></div>
</div>
<!-- Verification Prompt Form -->
<div id="verifyForm" class="d-none text-center">
<h5 class="text-dark fw-bold mb-3">Verify Your Email Address</h5>
<p class="text-dark">📩 A verification link has been sent to <strong id="verificationEmailSentTo">your_email@example.com</strong>.</p>
<p class="text-muted">Please check your email inbox (and spam/junk folder) and click the verification link provided by Firebase to activate your account.</p>
<p class="text-muted mt-3">Once you've clicked the link, return here and click the button below.</p>
<button type="button" class="btn btn-success mt-3" id="verifyContinueBtn" data-original-text="I’ve Verified My Email">I’ve Verified My Email</button>
<hr class="my-3">
<button type="button" class="btn btn-sm btn-outline-secondary" id="resendVerificationBtn" data-original-text="Resend Verification Email">Resend Verification Email</button>
<div class="text-center mt-3"><a href="#!" onclick="showForm('loginForm')">Back to Login</a></div>
</div>
<!-- Forgot Password Form -->
<div id="forgotForm" class="d-none">
<form id="forgotFormElement">
<div class="mb-3">
<input type="email" class="form-control" id="forgotEmail" placeholder="Enter your email" required />
</div>
<button type="submit" class="btn btn-primary w-100" data-original-text="Reset Password">Reset Password</button>
</form>
<div class="text-center mt-3"><a href="#!" onclick="showForm('loginForm')">Back to Login</a></div>
</div>
</div>
</div>
</div>
</div>
<!-- Scripts -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.8.1/firebase-app.js";
import {
getAuth,
setPersistence,
browserLocalPersistence,
browserSessionPersistence,
signInWithEmailAndPassword,
createUserWithEmailAndPassword,
sendPasswordResetEmail,
sendEmailVerification
} from "https://www.gstatic.com/firebasejs/11.8.1/firebase-auth.js";
// Import Firestore query functions
import { getFirestore, doc, setDoc, serverTimestamp, collection, query, where, getDocs, limit } from "https://www.gstatic.com/firebasejs/11.8.1/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyDv1S-UU0-CORLOYEaOIYqh5YqgjxXHIqs", // Redacted in thought process, kept as is from user input
authDomain: "ghatparstore.firebaseapp.com",
projectId: "ghatparstore",
storageBucket: "ghatparstore.appspot.com",
messagingSenderId: "395013404803",
appId: "1:395013404803:web:b8fa605483e94a1a30c3b6",
measurementId: "G-RYNRH76Z97",
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const auth = getAuth(app);
// --- Global showPopup function (defined outside DOMContentLoaded) ---
function showPopup(message = "Notification", type = "info") { // Added type parameter
const popup = document.getElementById("popupMessage");
if (!popup) {
console.error("Popup message element not found!");
alert(message);
return;
}
popup.textContent = message;
// Apply type class for different styling (e.g., success, error, warning)
popup.className = 'popup-message show'; // Reset classes first
if (type === 'success') popup.classList.add('bg-success', 'text-white');
else if (type === 'error') popup.classList.add('bg-danger', 'text-white');
else if (type === 'warning') popup.classList.add('bg-warning', 'text-dark');
else popup.classList.add('bg-light', 'text-dark'); // Default info style
if (popup.dataset.timeoutId) {
clearTimeout(parseInt(popup.dataset.timeoutId));
}
const timeoutId = setTimeout(() => {
popup.classList.remove("show", "bg-success", "bg-danger", "bg-warning", "bg-light", "text-white", "text-dark");
popup.classList.add("hide");
popup.dataset.timeoutId = "";
}, 3500);
popup.dataset.timeoutId = timeoutId.toString();
}
// Make showPopup globally accessible if other non-module scripts might use it
window.showPopup = showPopup;
document.addEventListener("DOMContentLoaded", () => {
const loginFormEl = document.getElementById("loginFormElement");
const signupFormEl = document.getElementById("signupFormElement");
const forgotFormEl = document.getElementById("forgotFormElement");
const passwordInput = document.getElementById("password");
const confirmPasswordInput = document.getElementById("confirmPassword");
const togglePasswordBtn = document.getElementById("togglePassword");
const toggleConfirmPasswordBtn = document.getElementById("toggleConfirmPassword");
const passwordMatchWarning = document.getElementById("passwordMatchWarning");
const verifyContinueBtn = document.getElementById("verifyContinueBtn");
const verificationEmailSentToEl = document.getElementById("verificationEmailSentTo");
const resendVerificationBtn = document.getElementById("resendVerificationBtn");
togglePasswordBtn?.addEventListener("click", () => {
const type = passwordInput.type === "password" ? "text" : "password";
passwordInput.type = type;
togglePasswordBtn.firstElementChild.className = type === "password" ? "fas fa-eye" : "fas fa-eye-slash";
});
toggleConfirmPasswordBtn?.addEventListener("click", () => {
const type = confirmPasswordInput.type === "password" ? "text" : "password";
confirmPasswordInput.type = type;
toggleConfirmPasswordBtn.firstElementChild.className = type === "password" ? "fas fa-eye" : "fas fa-eye-slash";
});
const validatePasswords = () => {
if (!passwordInput.value && !confirmPasswordInput.value) {
passwordMatchWarning.classList.add("visually-hidden");
return;
}
if (passwordInput.value !== confirmPasswordInput.value && confirmPasswordInput.value) {
passwordMatchWarning.classList.remove("visually-hidden");
} else {
passwordMatchWarning.classList.add("visually-hidden");
}
};
passwordInput?.addEventListener("input", validatePasswords);
confirmPasswordInput?.addEventListener("input", validatePasswords);
const setLoading = (element, isLoading, isButton = true) => {
if (!element) return;
element.disabled = isLoading;
const originalText = element.getAttribute("data-original-text") || (isButton ? element.innerText : "");
if (isButton && !element.getAttribute("data-original-text")) {
element.setAttribute("data-original-text", element.innerText);
}
element.innerHTML = isLoading ? `<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Loading...` : originalText;
};
const clearErrorMessages = (form) => {
form.querySelectorAll(".form-text.text-danger").forEach(el => {
el.classList.add("visually-hidden");
el.textContent = "";
});
passwordMatchWarning.classList.add("visually-hidden");
};
window.showForm = (formId, emailForVerification = null) => {
const allForms = ['loginForm', 'signupForm', 'forgotForm', 'verifyForm'];
allForms.forEach(id => {
const formElement = document.getElementById(id);
if (formElement) formElement.classList.add("d-none");
});
const targetForm = document.getElementById(formId);
if (targetForm) targetForm.classList.remove("d-none");
const titleMap = {
loginForm: "Login",
signupForm: "Sign Up",
forgotForm: "Reset Password",
verifyForm: "Verify Your Email"
};
document.getElementById("authModalTitle").innerText = titleMap[formId] || "Authentication";
if (formId !== 'verifyForm' && targetForm && targetForm.querySelector('form')) {
clearErrorMessages(targetForm.querySelector('form'));
}
if (formId === 'verifyForm' && emailForVerification) {
verificationEmailSentToEl.textContent = emailForVerification;
}
};
verifyContinueBtn.addEventListener("click", async () => {
const currentUser = auth.currentUser;
if (!currentUser) {
showPopup("No user is currently signed in. Please sign up or log in.", "warning");
window.showForm("loginForm");
return;
}
setLoading(verifyContinueBtn, true);
try {
await currentUser.reload();
if (currentUser.emailVerified) {
showPopup("Email verified successfully! You can now login or proceed.", "success");
const authModalEl = document.getElementById('authModal');
const authModal = bootstrap.Modal.getInstance(authModalEl);
if (authModal) authModal.hide();
window.location.href = "dashboard.html";
} else {
showPopup("Email not verified yet. Please check your email and click the verification link.", "warning");
}
} catch (error) {
console.error("Error checking email verification:", error);
showPopup("Error checking verification status: " + error.message, "error");
} finally {
setLoading(verifyContinueBtn, false);
}
});
resendVerificationBtn.addEventListener("click", async () => {
const currentUser = auth.currentUser;
if (currentUser && !currentUser.emailVerified) {
setLoading(resendVerificationBtn, true);
try {
await sendEmailVerification(currentUser);
showPopup("Verification email resent to " + currentUser.email + ". Please check your inbox.", "success");
} catch (error) {
console.error("Error resending verification email:", error);
showPopup("Failed to resend verification email: " + error.message, "error");
} finally {
setLoading(resendVerificationBtn, false);
}
} else if (currentUser && currentUser.emailVerified) {
showPopup("Your email is already verified.", "info");
} else {
showPopup("No user found to resend verification. Please sign up or log in.", "warning");
window.showForm('loginForm');
}
});
loginFormEl.addEventListener("submit", async (e) => {
e.preventDefault();
clearErrorMessages(loginFormEl);
const email = loginFormEl.querySelector("#loginEmail").value.trim();
const password = loginFormEl.querySelector("#loginPassword").value;
const rememberMeChecked = document.getElementById("rememberMe").checked;
setLoading(loginFormEl.querySelector("button[type='submit']"), true);
try {
await setPersistence(auth, rememberMeChecked ? browserLocalPersistence : browserSessionPersistence);
const userCredential = await signInWithEmailAndPassword(auth, email, password);
const user = userCredential.user;
if (!user.emailVerified) {
showPopup("Please verify your email before logging in. A new verification link has been sent.", "warning");
await sendEmailVerification(user);
window.showForm("verifyForm", user.email);
setLoading(loginFormEl.querySelector("button[type='submit']"), false);
return;
}
const authModalEl = document.getElementById('authModal');
const authModal = bootstrap.Modal.getInstance(authModalEl);
if (authModal) authModal.hide();
window.location.href = "dashboard.html";
} catch (error) {
console.error("Login error: ", error);
showPopup("Login failed: " + (error.code === 'auth/invalid-credential' || error.code === 'auth/user-not-found' || error.code === 'auth/wrong-password' ? 'Invalid email or password.' : error.message), "error");
} finally {
const loginButton = loginFormEl.querySelector("button[type='submit']");
if (loginButton.disabled) {
setLoading(loginButton, false);
}
}
});
signupFormEl.addEventListener("submit", async (e) => {
e.preventDefault();
clearErrorMessages(signupFormEl);
const fullname = document.getElementById("fullname").value.trim();
const countryCode = document.getElementById("countryCode").value;
const number = document.getElementById("number").value.trim();
const signupInputEmail = document.getElementById("signupEmail").value.trim();
const pass = passwordInput.value;
const confirmPass = confirmPasswordInput.value;
let isValid = true;
if (!fullname) {
document.getElementById("fullnameError").textContent = "Full name is required.";
document.getElementById("fullnameError").classList.remove("visually-hidden"); isValid = false;
}
if (!signupInputEmail) {
document.getElementById("emailError").textContent = "Email is required.";
document.getElementById("emailError").classList.remove("visually-hidden"); isValid = false;
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(signupInputEmail)) {
document.getElementById("emailError").textContent = "Please enter a valid email address.";
document.getElementById("emailError").classList.remove("visually-hidden"); isValid = false;
}
const phonePattern = /^\d{7,15}$/;
if (!phonePattern.test(number)) {
document.getElementById("phoneError").textContent = "Valid phone number is required (7-15 digits).";
document.getElementById("phoneError").classList.remove("visually-hidden"); isValid = false;
}
if (pass.length < 6) {
document.getElementById("passwordError").textContent = "Password must be at least 6 characters.";
document.getElementById("passwordError").classList.remove("visually-hidden"); isValid = false;
}
if (pass !== confirmPass) {
document.getElementById("passwordMatchWarning").classList.remove("visually-hidden");
document.getElementById("confirmPasswordError").textContent = "Passwords do not match.";
document.getElementById("confirmPasswordError").classList.remove("visually-hidden"); isValid = false;
}
if (!isValid) return;
const signupButton = signupFormEl.querySelector("button[type='submit']");
setLoading(signupButton, true);
try {
const fullPhoneNumber = countryCode + number;
const usersRef = collection(db, "users");
// Check 1: Phone number existence (depends on Firestore 'list' rule for /users/*)
const phoneQuery = query(usersRef, where("phone", "==", fullPhoneNumber), limit(1));
const phoneQuerySnapshot = await getDocs(phoneQuery);
if (!phoneQuerySnapshot.empty) {
showPopup("This phone number is already registered. Please use a different phone number or try logging in.", "error");
document.getElementById("phoneError").textContent = "Phone number already registered.";
document.getElementById("phoneError").classList.remove("visually-hidden");
setLoading(signupButton, false);
return;
}
// If checks pass, proceed to create user
const userCredential = await createUserWithEmailAndPassword(auth, signupInputEmail, pass);
const user = userCredential.user;
await sendEmailVerification(user);
// This setDoc operation (line 552 in original error) depends on Firestore 'create' rule for /users/{userId}
await setDoc(doc(db, "users", user.uid), {
uid: user.uid,
fullname: fullname,
email: signupInputEmail,
phone: fullPhoneNumber,
emailVerified: user.emailVerified,
createdAt: serverTimestamp(),
});
showPopup("Account created! Please check your email (" + signupInputEmail + ") to verify your account.", "success");
window.showForm("verifyForm", signupInputEmail);
} catch (error) {
console.error("Signup error: ", error);
let userMessage = "Signup failed. Please try again.";
if (error.code === 'auth/email-already-in-use') {
userMessage = "This email is already registered. Try logging in or use a different email.";
document.getElementById("emailError").textContent = userMessage;
document.getElementById("emailError").classList.remove("visually-hidden");
} else if (error.code === 'auth/weak-password') {
userMessage = "Password is too weak. Please choose a stronger password.";
document.getElementById("passwordError").textContent = userMessage;
document.getElementById("passwordError").classList.remove("visually-hidden");
} else if (error.code === 'permission-denied' || (error.message && error.message.toLowerCase().includes("insufficient permission"))) {
userMessage = "Signup process failed due to a permission issue. Please check Firestore rules or contact support.";
} else {
userMessage = "Signup failed: " + error.message;
}
showPopup(userMessage, "error");
} finally {
setLoading(signupButton, false);
}
});
forgotFormEl.addEventListener("submit", async (e) => {
e.preventDefault();
clearErrorMessages(forgotFormEl);
const email = forgotFormEl.querySelector("#forgotEmail").value.trim();
if (!email) {
showPopup("Please enter your email address.", "warning");
return;
}
setLoading(forgotFormEl.querySelector("button[type='submit']"), true);
try {
await sendPasswordResetEmail(auth, email);
showPopup("Password reset email sent to " + email + "! Please check your inbox.", "success");
window.showForm("loginForm");
} catch (error) {
console.error("Password Reset Error:", error);
showPopup("Error sending reset email: " + (error.code === 'auth/user-not-found' ? 'No user found with this email.' : error.message), "error");
} finally {
setLoading(forgotFormEl.querySelector("button[type='submit']"), false);
}
});
});
</script>
</body>
</html>