Spaces:
Sleeping
Sleeping
fix login.html
Browse files- web/login.html +279 -275
web/login.html
CHANGED
|
@@ -1,276 +1,280 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8" />
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
-
<title>Login / Signup - CTRL + ALT + HEAL</title>
|
| 7 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
-
<link
|
| 9 |
-
href="https://fonts.googleapis.com/css2?family=Rubik:wght@400;700&display=swap"
|
| 10 |
-
rel="stylesheet"
|
| 11 |
-
/>
|
| 12 |
-
<style>
|
| 13 |
-
:root {
|
| 14 |
-
--tropical-indigo: rgb(120, 187, 242);
|
| 15 |
-
--wisteria: rgb(197, 217, 251);
|
| 16 |
-
--latte-cream: #ffffff;
|
| 17 |
-
}
|
| 18 |
-
body {
|
| 19 |
-
font-family: "Rubik", sans-serif;
|
| 20 |
-
background-color: var(--latte-cream);
|
| 21 |
-
color: #333;
|
| 22 |
-
}
|
| 23 |
-
.glass-card {
|
| 24 |
-
background: rgba(162, 160, 160, 0.075);
|
| 25 |
-
backdrop-filter: blur(12px);
|
| 26 |
-
border-radius: 1rem;
|
| 27 |
-
border: 1px solid rgba(255, 255, 255, 0.3);
|
| 28 |
-
padding: 2rem;
|
| 29 |
-
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
| 30 |
-
}
|
| 31 |
-
.glass-card:hover {
|
| 32 |
-
transform: translateY(-5px);
|
| 33 |
-
box-shadow: 0 15px 25px rgba(0, 0, 0, 0.2);
|
| 34 |
-
}
|
| 35 |
-
.nav-link {
|
| 36 |
-
position: relative;
|
| 37 |
-
padding-bottom: 4px;
|
| 38 |
-
transition: color 0.3s;
|
| 39 |
-
}
|
| 40 |
-
.nav-link::after {
|
| 41 |
-
content: "";
|
| 42 |
-
position: absolute;
|
| 43 |
-
width: 0%;
|
| 44 |
-
height: 2px;
|
| 45 |
-
bottom: 0;
|
| 46 |
-
left: 0;
|
| 47 |
-
background-color: var(--tropical-indigo);
|
| 48 |
-
transition: width 0.3s ease;
|
| 49 |
-
}
|
| 50 |
-
.nav-link:hover::after {
|
| 51 |
-
width: 100%;
|
| 52 |
-
}
|
| 53 |
-
.nav-link.active-page::after {
|
| 54 |
-
width: 100%;
|
| 55 |
-
}
|
| 56 |
-
</style>
|
| 57 |
-
</head>
|
| 58 |
-
<body class="min-h-screen flex flex-col">
|
| 59 |
-
<!-- NAVBAR -->
|
| 60 |
-
<nav
|
| 61 |
-
class="fixed top-0 left-0 w-full z-50 backdrop-blur-md bg-white/20 border-b border-white/30 shadow-md"
|
| 62 |
-
>
|
| 63 |
-
<div class="flex justify-between items-center w-full px-6 py-4">
|
| 64 |
-
<a
|
| 65 |
-
href="index.html"
|
| 66 |
-
class="text-2xl font-bold text-black hover:text-[var(--tropical-indigo)] transition"
|
| 67 |
-
>
|
| 68 |
-
CTRL + ALT + HEAL
|
| 69 |
-
</a>
|
| 70 |
-
<!-- Desktop Menu -->
|
| 71 |
-
<ul class="hidden md:flex space-x-6 font-medium text-gray-800">
|
| 72 |
-
<li><a href="index.html" class="nav-link">Home</a></li>
|
| 73 |
-
<li><a href="profile.html" class="nav-link">Profile</a></li>
|
| 74 |
-
<li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
|
| 75 |
-
<li><a href="past_data.html" class="nav-link">Past Report</a></li>
|
| 76 |
-
|
| 77 |
-
<button
|
| 78 |
-
id="hamburger"
|
| 79 |
-
class="md:hidden text-[var(--latte-cream)] text-2xl"
|
| 80 |
-
>
|
| 81 |
-
☰
|
| 82 |
-
</button>
|
| 83 |
-
</div>
|
| 84 |
-
<ul
|
| 85 |
-
id="mobile-menu"
|
| 86 |
-
class="hidden flex-col space-y-4 bg-white/30 backdrop-blur-lg border border-white/20 rounded-xl shadow-lg mt-2 p-4 mx-6 md:hidden"
|
| 87 |
-
>
|
| 88 |
-
<li><a href="index.html" class="block text-gray-800">Home</a></li>
|
| 89 |
-
<li>
|
| 90 |
-
<a href="analyzer.html" class="block text-gray-800">Analyzer</a>
|
| 91 |
-
</li>
|
| 92 |
-
<li><a href="profile.html" class="block text-gray-800">Profile</a></li>
|
| 93 |
-
<li>
|
| 94 |
-
<a href="login.html" class="block text-gray-800 active-page">Login</a>
|
| 95 |
-
</li>
|
| 96 |
-
</ul>
|
| 97 |
-
</nav>
|
| 98 |
-
|
| 99 |
-
<!-- LOGIN FORM -->
|
| 100 |
-
<main class="flex flex-1 items-center justify-center pt-28 px-6">
|
| 101 |
-
<div class="glass-card w-full max-w-md text-center">
|
| 102 |
-
<h2 class="text-3xl font-bold text-[var(--tropical-indigo)] mb-6">
|
| 103 |
-
Sign In / Sign Up
|
| 104 |
-
</h2>
|
| 105 |
-
<select
|
| 106 |
-
id="modeSelector"
|
| 107 |
-
onchange="toggleMode(this.value)"
|
| 108 |
-
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 109 |
-
>
|
| 110 |
-
<option value="login">Log In</option>
|
| 111 |
-
<option value="signup">Sign Up</option>
|
| 112 |
-
</select>
|
| 113 |
-
|
| 114 |
-
<input
|
| 115 |
-
type="email"
|
| 116 |
-
id="email"
|
| 117 |
-
placeholder="Email"
|
| 118 |
-
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 119 |
-
/>
|
| 120 |
-
<input
|
| 121 |
-
type="password"
|
| 122 |
-
id="password"
|
| 123 |
-
placeholder="Password"
|
| 124 |
-
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 125 |
-
/>
|
| 126 |
-
|
| 127 |
-
<div id="nameGroup" style="display: none">
|
| 128 |
-
<input
|
| 129 |
-
type="text"
|
| 130 |
-
id="name"
|
| 131 |
-
placeholder="Full Name"
|
| 132 |
-
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 133 |
-
/>
|
| 134 |
-
</div>
|
| 135 |
-
|
| 136 |
-
<div id="dobGroup" style="display: none">
|
| 137 |
-
<input
|
| 138 |
-
type="date"
|
| 139 |
-
id="dob"
|
| 140 |
-
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 141 |
-
/>
|
| 142 |
-
</div>
|
| 143 |
-
|
| 144 |
-
<p id="error-message" class="text-red-500 text-sm mb-4"></p>
|
| 145 |
-
|
| 146 |
-
<button
|
| 147 |
-
id="submitBtn"
|
| 148 |
-
class="w-full bg-[var(--tropical-indigo)] text-white py-2 rounded-lg hover:bg-[var(--wisteria)] mb-2"
|
| 149 |
-
>
|
| 150 |
-
Log In
|
| 151 |
-
</button>
|
| 152 |
-
<button
|
| 153 |
-
onclick="resetPassword()"
|
| 154 |
-
class="w-full bg-gray-200 text-gray-800 py-2 rounded-lg hover:bg-gray-300"
|
| 155 |
-
>
|
| 156 |
-
Reset Password
|
| 157 |
-
</button>
|
| 158 |
-
</div>
|
| 159 |
-
</main>
|
| 160 |
-
|
| 161 |
-
<!-- FOOTER -->
|
| 162 |
-
<footer class="py-6 bg-[var(--wisteria)] text-white text-center">
|
| 163 |
-
© 2025 CTRL + ALT + HEAL. All rights reserved.
|
| 164 |
-
</footer>
|
| 165 |
-
|
| 166 |
-
<script type="module">
|
| 167 |
-
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js";
|
| 168 |
-
import {
|
| 169 |
-
getAuth,
|
| 170 |
-
createUserWithEmailAndPassword,
|
| 171 |
-
signInWithEmailAndPassword,
|
| 172 |
-
sendPasswordResetEmail,
|
| 173 |
-
} from "https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js";
|
| 174 |
-
import {
|
| 175 |
-
getFirestore,
|
| 176 |
-
doc,
|
| 177 |
-
setDoc,
|
| 178 |
-
} from "https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js";
|
| 179 |
-
|
| 180 |
-
const firebaseConfig = {
|
| 181 |
-
apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
|
| 182 |
-
authDomain: "login-tutorial-7a9e1.firebaseapp.com",
|
| 183 |
-
projectId: "login-tutorial-7a9e1",
|
| 184 |
-
storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
|
| 185 |
-
messagingSenderId: "491093197824",
|
| 186 |
-
appId: "1:491093197824:web:9f866...",
|
| 187 |
-
};
|
| 188 |
-
|
| 189 |
-
const app = initializeApp(firebaseConfig);
|
| 190 |
-
const auth = getAuth(app);
|
| 191 |
-
const db = getFirestore(app);
|
| 192 |
-
|
| 193 |
-
let mode = "login";
|
| 194 |
-
const nameGroup = document.getElementById("nameGroup");
|
| 195 |
-
const dobGroup = document.getElementById("dobGroup");
|
| 196 |
-
const actionBtn = document.getElementById("submitBtn");
|
| 197 |
-
const errorElement = document.getElementById("error-message");
|
| 198 |
-
|
| 199 |
-
window.toggleMode = (newMode) => {
|
| 200 |
-
mode = newMode;
|
| 201 |
-
if (mode === "signup") {
|
| 202 |
-
nameGroup.style.display = "block";
|
| 203 |
-
dobGroup.style.display = "block";
|
| 204 |
-
actionBtn.textContent = "Sign Up";
|
| 205 |
-
} else {
|
| 206 |
-
nameGroup.style.display = "none";
|
| 207 |
-
dobGroup.style.display = "none";
|
| 208 |
-
actionBtn.textContent = "Log In";
|
| 209 |
-
}
|
| 210 |
-
};
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
const getFriendlyErrorMessage = (error) => {
|
| 214 |
-
switch (error.code) {
|
| 215 |
-
case 'auth/invalid-email':
|
| 216 |
-
return 'Invalid email format. Please try again.';
|
| 217 |
-
case 'auth/user-not-found':
|
| 218 |
-
return 'No user found with this email.';
|
| 219 |
-
case 'auth/wrong-password':
|
| 220 |
-
return 'Incorrect password. Please try again.';
|
| 221 |
-
case 'auth/weak-password':
|
| 222 |
-
return 'Password is too weak. Please use at least 6 characters.';
|
| 223 |
-
case 'auth/invalid-login-credentials':
|
| 224 |
-
return 'Invalid email or password. Please try again.';
|
| 225 |
-
|
| 226 |
-
return '
|
| 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 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Login / Signup - CTRL + ALT + HEAL</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link
|
| 9 |
+
href="https://fonts.googleapis.com/css2?family=Rubik:wght@400;700&display=swap"
|
| 10 |
+
rel="stylesheet"
|
| 11 |
+
/>
|
| 12 |
+
<style>
|
| 13 |
+
:root {
|
| 14 |
+
--tropical-indigo: rgb(120, 187, 242);
|
| 15 |
+
--wisteria: rgb(197, 217, 251);
|
| 16 |
+
--latte-cream: #ffffff;
|
| 17 |
+
}
|
| 18 |
+
body {
|
| 19 |
+
font-family: "Rubik", sans-serif;
|
| 20 |
+
background-color: var(--latte-cream);
|
| 21 |
+
color: #333;
|
| 22 |
+
}
|
| 23 |
+
.glass-card {
|
| 24 |
+
background: rgba(162, 160, 160, 0.075);
|
| 25 |
+
backdrop-filter: blur(12px);
|
| 26 |
+
border-radius: 1rem;
|
| 27 |
+
border: 1px solid rgba(255, 255, 255, 0.3);
|
| 28 |
+
padding: 2rem;
|
| 29 |
+
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
| 30 |
+
}
|
| 31 |
+
.glass-card:hover {
|
| 32 |
+
transform: translateY(-5px);
|
| 33 |
+
box-shadow: 0 15px 25px rgba(0, 0, 0, 0.2);
|
| 34 |
+
}
|
| 35 |
+
.nav-link {
|
| 36 |
+
position: relative;
|
| 37 |
+
padding-bottom: 4px;
|
| 38 |
+
transition: color 0.3s;
|
| 39 |
+
}
|
| 40 |
+
.nav-link::after {
|
| 41 |
+
content: "";
|
| 42 |
+
position: absolute;
|
| 43 |
+
width: 0%;
|
| 44 |
+
height: 2px;
|
| 45 |
+
bottom: 0;
|
| 46 |
+
left: 0;
|
| 47 |
+
background-color: var(--tropical-indigo);
|
| 48 |
+
transition: width 0.3s ease;
|
| 49 |
+
}
|
| 50 |
+
.nav-link:hover::after {
|
| 51 |
+
width: 100%;
|
| 52 |
+
}
|
| 53 |
+
.nav-link.active-page::after {
|
| 54 |
+
width: 100%;
|
| 55 |
+
}
|
| 56 |
+
</style>
|
| 57 |
+
</head>
|
| 58 |
+
<body class="min-h-screen flex flex-col">
|
| 59 |
+
<!-- NAVBAR -->
|
| 60 |
+
<nav
|
| 61 |
+
class="fixed top-0 left-0 w-full z-50 backdrop-blur-md bg-white/20 border-b border-white/30 shadow-md"
|
| 62 |
+
>
|
| 63 |
+
<div class="flex justify-between items-center w-full px-6 py-4">
|
| 64 |
+
<a
|
| 65 |
+
href="index.html"
|
| 66 |
+
class="text-2xl font-bold text-black hover:text-[var(--tropical-indigo)] transition"
|
| 67 |
+
>
|
| 68 |
+
CTRL + ALT + HEAL
|
| 69 |
+
</a>
|
| 70 |
+
<!-- Desktop Menu -->
|
| 71 |
+
<ul class="hidden md:flex space-x-6 font-medium text-gray-800">
|
| 72 |
+
<li><a href="index.html" class="nav-link">Home</a></li>
|
| 73 |
+
<li><a href="profile.html" class="nav-link">Profile</a></li>
|
| 74 |
+
<li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
|
| 75 |
+
<li><a href="past_data.html" class="nav-link">Past Report</a></li>
|
| 76 |
+
|
| 77 |
+
<button
|
| 78 |
+
id="hamburger"
|
| 79 |
+
class="md:hidden text-[var(--latte-cream)] text-2xl"
|
| 80 |
+
>
|
| 81 |
+
☰
|
| 82 |
+
</button>
|
| 83 |
+
</div>
|
| 84 |
+
<ul
|
| 85 |
+
id="mobile-menu"
|
| 86 |
+
class="hidden flex-col space-y-4 bg-white/30 backdrop-blur-lg border border-white/20 rounded-xl shadow-lg mt-2 p-4 mx-6 md:hidden"
|
| 87 |
+
>
|
| 88 |
+
<li><a href="index.html" class="block text-gray-800">Home</a></li>
|
| 89 |
+
<li>
|
| 90 |
+
<a href="analyzer.html" class="block text-gray-800">Analyzer</a>
|
| 91 |
+
</li>
|
| 92 |
+
<li><a href="profile.html" class="block text-gray-800">Profile</a></li>
|
| 93 |
+
<li>
|
| 94 |
+
<a href="login.html" class="block text-gray-800 active-page">Login</a>
|
| 95 |
+
</li>
|
| 96 |
+
</ul>
|
| 97 |
+
</nav>
|
| 98 |
+
|
| 99 |
+
<!-- LOGIN FORM -->
|
| 100 |
+
<main class="flex flex-1 items-center justify-center pt-28 px-6">
|
| 101 |
+
<div class="glass-card w-full max-w-md text-center">
|
| 102 |
+
<h2 class="text-3xl font-bold text-[var(--tropical-indigo)] mb-6">
|
| 103 |
+
Sign In / Sign Up
|
| 104 |
+
</h2>
|
| 105 |
+
<select
|
| 106 |
+
id="modeSelector"
|
| 107 |
+
onchange="toggleMode(this.value)"
|
| 108 |
+
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 109 |
+
>
|
| 110 |
+
<option value="login">Log In</option>
|
| 111 |
+
<option value="signup">Sign Up</option>
|
| 112 |
+
</select>
|
| 113 |
+
|
| 114 |
+
<input
|
| 115 |
+
type="email"
|
| 116 |
+
id="email"
|
| 117 |
+
placeholder="Email"
|
| 118 |
+
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 119 |
+
/>
|
| 120 |
+
<input
|
| 121 |
+
type="password"
|
| 122 |
+
id="password"
|
| 123 |
+
placeholder="Password"
|
| 124 |
+
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 125 |
+
/>
|
| 126 |
+
|
| 127 |
+
<div id="nameGroup" style="display: none">
|
| 128 |
+
<input
|
| 129 |
+
type="text"
|
| 130 |
+
id="name"
|
| 131 |
+
placeholder="Full Name"
|
| 132 |
+
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 133 |
+
/>
|
| 134 |
+
</div>
|
| 135 |
+
|
| 136 |
+
<div id="dobGroup" style="display: none">
|
| 137 |
+
<input
|
| 138 |
+
type="date"
|
| 139 |
+
id="dob"
|
| 140 |
+
class="w-full mb-4 px-4 py-2 border rounded-lg"
|
| 141 |
+
/>
|
| 142 |
+
</div>
|
| 143 |
+
|
| 144 |
+
<p id="error-message" class="text-red-500 text-sm mb-4"></p>
|
| 145 |
+
|
| 146 |
+
<button
|
| 147 |
+
id="submitBtn"
|
| 148 |
+
class="w-full bg-[var(--tropical-indigo)] text-white py-2 rounded-lg hover:bg-[var(--wisteria)] mb-2"
|
| 149 |
+
>
|
| 150 |
+
Log In
|
| 151 |
+
</button>
|
| 152 |
+
<button
|
| 153 |
+
onclick="resetPassword()"
|
| 154 |
+
class="w-full bg-gray-200 text-gray-800 py-2 rounded-lg hover:bg-gray-300"
|
| 155 |
+
>
|
| 156 |
+
Reset Password
|
| 157 |
+
</button>
|
| 158 |
+
</div>
|
| 159 |
+
</main>
|
| 160 |
+
|
| 161 |
+
<!-- FOOTER -->
|
| 162 |
+
<footer class="py-6 bg-[var(--wisteria)] text-white text-center">
|
| 163 |
+
© 2025 CTRL + ALT + HEAL. All rights reserved.
|
| 164 |
+
</footer>
|
| 165 |
+
|
| 166 |
+
<script type="module">
|
| 167 |
+
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js";
|
| 168 |
+
import {
|
| 169 |
+
getAuth,
|
| 170 |
+
createUserWithEmailAndPassword,
|
| 171 |
+
signInWithEmailAndPassword,
|
| 172 |
+
sendPasswordResetEmail,
|
| 173 |
+
} from "https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js";
|
| 174 |
+
import {
|
| 175 |
+
getFirestore,
|
| 176 |
+
doc,
|
| 177 |
+
setDoc,
|
| 178 |
+
} from "https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js";
|
| 179 |
+
|
| 180 |
+
const firebaseConfig = {
|
| 181 |
+
apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
|
| 182 |
+
authDomain: "login-tutorial-7a9e1.firebaseapp.com",
|
| 183 |
+
projectId: "login-tutorial-7a9e1",
|
| 184 |
+
storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
|
| 185 |
+
messagingSenderId: "491093197824",
|
| 186 |
+
appId: "1:491093197824:web:9f866...",
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
const app = initializeApp(firebaseConfig);
|
| 190 |
+
const auth = getAuth(app);
|
| 191 |
+
const db = getFirestore(app);
|
| 192 |
+
|
| 193 |
+
let mode = "login";
|
| 194 |
+
const nameGroup = document.getElementById("nameGroup");
|
| 195 |
+
const dobGroup = document.getElementById("dobGroup");
|
| 196 |
+
const actionBtn = document.getElementById("submitBtn");
|
| 197 |
+
const errorElement = document.getElementById("error-message");
|
| 198 |
+
|
| 199 |
+
window.toggleMode = (newMode) => {
|
| 200 |
+
mode = newMode;
|
| 201 |
+
if (mode === "signup") {
|
| 202 |
+
nameGroup.style.display = "block";
|
| 203 |
+
dobGroup.style.display = "block";
|
| 204 |
+
actionBtn.textContent = "Sign Up";
|
| 205 |
+
} else {
|
| 206 |
+
nameGroup.style.display = "none";
|
| 207 |
+
dobGroup.style.display = "none";
|
| 208 |
+
actionBtn.textContent = "Log In";
|
| 209 |
+
}
|
| 210 |
+
};
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
const getFriendlyErrorMessage = (error) => {
|
| 214 |
+
switch (error.code) {
|
| 215 |
+
case 'auth/invalid-email':
|
| 216 |
+
return 'Invalid email format. Please try again.';
|
| 217 |
+
case 'auth/user-not-found':
|
| 218 |
+
return 'No user found with this email.';
|
| 219 |
+
case 'auth/wrong-password':
|
| 220 |
+
return 'Incorrect password. Please try again.';
|
| 221 |
+
case 'auth/weak-password':
|
| 222 |
+
return 'Password is too weak. Please use at least 6 characters.';
|
| 223 |
+
case 'auth/invalid-login-credentials':
|
| 224 |
+
return 'Invalid email or password. Please try again.';
|
| 225 |
+
case 'auth/email-already-in-use':
|
| 226 |
+
return 'This email is already registered. Please log in or use a different email.';
|
| 227 |
+
case 'auth/email-already-exists':
|
| 228 |
+
return 'This email is already registered. Please log in or use a different email.';
|
| 229 |
+
default:
|
| 230 |
+
return 'An unknown error occurred. Please try again.';
|
| 231 |
+
}
|
| 232 |
+
};
|
| 233 |
+
|
| 234 |
+
actionBtn.addEventListener("click", async (e) => {
|
| 235 |
+
e.preventDefault();
|
| 236 |
+
const email = document.getElementById("email").value;
|
| 237 |
+
const password = document.getElementById("password").value;
|
| 238 |
+
errorElement.textContent = "";
|
| 239 |
+
|
| 240 |
+
if (mode === "signup") {
|
| 241 |
+
try {
|
| 242 |
+
const name = document.getElementById("name").value;
|
| 243 |
+
const dob = document.getElementById("dob").value;
|
| 244 |
+
const userCredential = await createUserWithEmailAndPassword(
|
| 245 |
+
auth,
|
| 246 |
+
email,
|
| 247 |
+
password
|
| 248 |
+
);
|
| 249 |
+
const user = userCredential.user;
|
| 250 |
+
await setDoc(doc(db, "users", user.uid), { name, email, dob });
|
| 251 |
+
window.location.href = "profile.html";
|
| 252 |
+
} catch (err) {
|
| 253 |
+
errorElement.textContent = getFriendlyErrorMessage(err);
|
| 254 |
+
}
|
| 255 |
+
} else {
|
| 256 |
+
try {
|
| 257 |
+
await signInWithEmailAndPassword(auth, email, password);
|
| 258 |
+
window.location.href = "profile.html";
|
| 259 |
+
} catch (err) {
|
| 260 |
+
errorElement.textContent = getFriendlyErrorMessage(err);
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
});
|
| 264 |
+
|
| 265 |
+
window.resetPassword = async () => {
|
| 266 |
+
const email = document.getElementById("email").value;
|
| 267 |
+
if (!email) {
|
| 268 |
+
errorElement.textContent = "Enter your email first!";
|
| 269 |
+
return;
|
| 270 |
+
}
|
| 271 |
+
try {
|
| 272 |
+
await sendPasswordResetEmail(auth, email);
|
| 273 |
+
alert("Password reset email sent!");
|
| 274 |
+
} catch (err) {
|
| 275 |
+
errorElement.textContent = err.message;
|
| 276 |
+
}
|
| 277 |
+
};
|
| 278 |
+
</script>
|
| 279 |
+
</body>
|
| 280 |
</html>
|