Spaces:
Running
Running
Update frontend/login.html
Browse files- frontend/login.html +261 -228
frontend/login.html
CHANGED
|
@@ -8,6 +8,107 @@
|
|
| 8 |
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
|
| 10 |
<link rel="stylesheet" href="style.css">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
</head>
|
| 12 |
|
| 13 |
<body class="register-page">
|
|
@@ -18,26 +119,27 @@
|
|
| 18 |
|
| 19 |
<h2>Welcome Back</h2>
|
| 20 |
|
| 21 |
-
<p class="sub-title" style="text-align:center;
|
| 22 |
Login to your Cortexa account
|
| 23 |
</p>
|
| 24 |
|
| 25 |
-
<!--
|
| 26 |
<input
|
| 27 |
type="email"
|
| 28 |
id="loginEmail"
|
| 29 |
placeholder="Email Address"
|
|
|
|
| 30 |
required
|
| 31 |
-
autofocus
|
| 32 |
>
|
| 33 |
|
| 34 |
-
<!--
|
| 35 |
<div class="password-wrapper">
|
| 36 |
|
| 37 |
<input
|
| 38 |
type="password"
|
| 39 |
id="loginPassword"
|
| 40 |
placeholder="Password"
|
|
|
|
| 41 |
required
|
| 42 |
>
|
| 43 |
|
|
@@ -50,311 +152,242 @@
|
|
| 50 |
|
| 51 |
</div>
|
| 52 |
|
| 53 |
-
<!--
|
| 54 |
-
<div class="form-options"
|
|
|
|
| 55 |
|
| 56 |
-
<label>
|
| 57 |
<input type="checkbox" id="rememberMe">
|
| 58 |
Remember me
|
| 59 |
</label>
|
| 60 |
|
| 61 |
-
<a href="#" id="forgotPassword"
|
|
|
|
| 62 |
Forgot password?
|
| 63 |
</a>
|
| 64 |
|
| 65 |
</div>
|
| 66 |
|
| 67 |
-
<!--
|
| 68 |
<div id="message" class="message"></div>
|
| 69 |
|
| 70 |
-
<!--
|
| 71 |
<button type="submit" id="loginBtn">
|
| 72 |
-
|
| 73 |
<span id="btnText">Login</span>
|
| 74 |
|
| 75 |
<span id="btnLoader" style="display:none;">
|
| 76 |
<span class="loader"></span>
|
| 77 |
Logging in...
|
| 78 |
</span>
|
| 79 |
-
|
| 80 |
</button>
|
| 81 |
|
| 82 |
-
<!--
|
| 83 |
-
<p class="register-link"
|
|
|
|
|
|
|
| 84 |
Don't have an account?
|
| 85 |
-
<a href="register.html"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
</p>
|
| 87 |
|
| 88 |
</form>
|
| 89 |
|
| 90 |
</div>
|
| 91 |
|
| 92 |
-
|
| 93 |
<script>
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
const loginForm = document.getElementById('loginForm');
|
| 100 |
-
const emailInput = document.getElementById('loginEmail');
|
| 101 |
-
const passwordInput = document.getElementById('loginPassword');
|
| 102 |
-
const rememberCheckbox = document.getElementById('rememberMe');
|
| 103 |
-
|
| 104 |
-
const loginBtn = document.getElementById('loginBtn');
|
| 105 |
-
const btnText = document.getElementById('btnText');
|
| 106 |
-
const btnLoader = document.getElementById('btnLoader');
|
| 107 |
-
const messageBox = document.getElementById('message');
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
// =====================================
|
| 111 |
-
// SHOW MESSAGE
|
| 112 |
-
// =====================================
|
| 113 |
-
|
| 114 |
-
function showMessage(text, type) {
|
| 115 |
-
|
| 116 |
-
messageBox.textContent = text;
|
| 117 |
-
messageBox.className = 'message ' + type;
|
| 118 |
-
messageBox.style.display = 'block';
|
| 119 |
-
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
// =====================================
|
| 124 |
-
// HIDE MESSAGE
|
| 125 |
-
// =====================================
|
| 126 |
-
|
| 127 |
-
function hideMessage() {
|
| 128 |
-
|
| 129 |
-
messageBox.textContent = '';
|
| 130 |
-
messageBox.className = 'message';
|
| 131 |
-
messageBox.style.display = 'none';
|
| 132 |
-
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
// =====================================
|
| 137 |
-
// PASSWORD VISIBILITY
|
| 138 |
-
// =====================================
|
| 139 |
-
|
| 140 |
-
document.getElementById('togglePassword').addEventListener('click', function() {
|
| 141 |
-
|
| 142 |
-
if (passwordInput.type === 'password') {
|
| 143 |
-
|
| 144 |
-
passwordInput.type = 'text';
|
| 145 |
-
this.textContent = '🙈';
|
| 146 |
-
this.setAttribute('aria-label', 'Hide password');
|
| 147 |
-
|
| 148 |
-
} else {
|
| 149 |
-
|
| 150 |
-
passwordInput.type = 'password';
|
| 151 |
-
this.textContent = '👁️';
|
| 152 |
-
this.setAttribute('aria-label', 'Show password');
|
| 153 |
-
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
});
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
// =====================================
|
| 160 |
-
// FORGOT PASSWORD
|
| 161 |
-
// =====================================
|
| 162 |
-
|
| 163 |
-
document.getElementById('forgotPassword').addEventListener('click', function(e) {
|
| 164 |
-
|
| 165 |
-
e.preventDefault();
|
| 166 |
-
|
| 167 |
-
showMessage('Password reset feature coming soon!', 'warning');
|
| 168 |
-
|
| 169 |
-
});
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
// =====================================
|
| 173 |
-
// LOGIN FUNCTION
|
| 174 |
-
// =====================================
|
| 175 |
-
|
| 176 |
-
loginForm.addEventListener('submit', async function(e) {
|
| 177 |
-
|
| 178 |
-
e.preventDefault();
|
| 179 |
-
|
| 180 |
-
hideMessage();
|
| 181 |
-
|
| 182 |
-
const email = emailInput.value.trim();
|
| 183 |
-
const password = passwordInput.value;
|
| 184 |
-
const rememberMe = rememberCheckbox.checked;
|
| 185 |
-
|
| 186 |
-
// Validation
|
| 187 |
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
-
|
| 191 |
-
return;
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
}
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
return;
|
| 201 |
-
|
| 202 |
}
|
| 203 |
|
| 204 |
-
|
|
|
|
| 205 |
|
| 206 |
-
|
| 207 |
-
return;
|
| 208 |
|
| 209 |
-
|
|
|
|
| 210 |
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
| 216 |
|
|
|
|
| 217 |
try {
|
|
|
|
| 218 |
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
'Content-Type': 'application/json'
|
| 227 |
-
},
|
| 228 |
-
|
| 229 |
-
body: JSON.stringify({
|
| 230 |
-
email: email,
|
| 231 |
-
password: password
|
| 232 |
-
})
|
| 233 |
-
|
| 234 |
-
});
|
| 235 |
-
|
| 236 |
-
// Read response safely
|
| 237 |
-
|
| 238 |
-
const data = await response.json();
|
| 239 |
-
|
| 240 |
-
if (!response.ok) {
|
| 241 |
-
|
| 242 |
-
const errorMsg = data.error || data.message || 'Invalid email or password.';
|
| 243 |
-
|
| 244 |
-
if (errorMsg.toLowerCase().includes('verify your email')) {
|
| 245 |
-
|
| 246 |
-
showMessage('📧 Please verify your email before logging in.', 'warning');
|
| 247 |
|
| 248 |
-
|
|
|
|
| 249 |
|
| 250 |
-
|
| 251 |
|
| 252 |
-
|
| 253 |
|
| 254 |
-
|
| 255 |
|
| 256 |
-
|
|
|
|
| 257 |
|
|
|
|
|
|
|
| 258 |
return;
|
| 259 |
-
|
| 260 |
}
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
if (!data.access_token || !data.user) {
|
| 265 |
-
|
| 266 |
-
showMessage('Invalid server response. Please contact support.', 'error');
|
| 267 |
return;
|
| 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 |
-
// Redirect to dashboard
|
| 299 |
-
|
| 300 |
-
setTimeout(function() {
|
| 301 |
-
|
| 302 |
-
window.location.href = 'dashboard.html';
|
| 303 |
-
|
| 304 |
-
}, 1500);
|
| 305 |
-
|
| 306 |
-
} catch (error) {
|
| 307 |
-
|
| 308 |
-
console.error('Login error:', error);
|
| 309 |
-
|
| 310 |
-
showMessage(
|
| 311 |
-
'❌ Unable to connect to the server. Check your connection and backend.',
|
| 312 |
-
'error'
|
| 313 |
-
);
|
| 314 |
-
|
| 315 |
-
} finally {
|
| 316 |
-
|
| 317 |
-
loginBtn.disabled = false;
|
| 318 |
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
| 321 |
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
});
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
// =====================================
|
| 328 |
-
// INITIALIZE PAGE
|
| 329 |
-
// =====================================
|
| 330 |
-
|
| 331 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 332 |
-
|
| 333 |
-
const savedEmail = localStorage.getItem('savedEmail');
|
| 334 |
-
|
| 335 |
-
if (savedEmail && localStorage.getItem('rememberMe') === 'true') {
|
| 336 |
|
| 337 |
-
|
| 338 |
-
|
| 339 |
|
| 340 |
-
|
|
|
|
| 341 |
|
| 342 |
-
|
| 343 |
|
| 344 |
-
|
| 345 |
|
| 346 |
-
|
|
|
|
|
|
|
| 347 |
|
| 348 |
if (registrationMessage) {
|
| 349 |
-
|
| 350 |
showMessage(registrationMessage, 'success');
|
| 351 |
-
|
| 352 |
}
|
| 353 |
|
| 354 |
-
console.log('Cortexa login
|
| 355 |
|
| 356 |
});
|
| 357 |
-
|
| 358 |
</script>
|
| 359 |
|
| 360 |
</body>
|
|
|
|
| 8 |
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
|
| 10 |
<link rel="stylesheet" href="style.css">
|
| 11 |
+
|
| 12 |
+
<!-- Login page click and layout fixes -->
|
| 13 |
+
<style>
|
| 14 |
+
.login-box {
|
| 15 |
+
position: relative !important;
|
| 16 |
+
z-index: 10 !important;
|
| 17 |
+
pointer-events: auto !important;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.login-box input,
|
| 21 |
+
.login-box button,
|
| 22 |
+
.login-box a {
|
| 23 |
+
pointer-events: auto !important;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
.login-box button[type="submit"] {
|
| 27 |
+
position: relative !important;
|
| 28 |
+
z-index: 20 !important;
|
| 29 |
+
width: 100% !important;
|
| 30 |
+
display: block !important;
|
| 31 |
+
cursor: pointer !important;
|
| 32 |
+
pointer-events: auto !important;
|
| 33 |
+
touch-action: manipulation;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.login-box button:disabled {
|
| 37 |
+
opacity: 0.7;
|
| 38 |
+
cursor: wait !important;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.login-box .password-wrapper {
|
| 42 |
+
position: relative;
|
| 43 |
+
width: 100%;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.login-box .password-wrapper input {
|
| 47 |
+
width: 100%;
|
| 48 |
+
box-sizing: border-box;
|
| 49 |
+
padding-right: 55px;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.login-box .toggle-password {
|
| 53 |
+
position: absolute !important;
|
| 54 |
+
right: 10px;
|
| 55 |
+
top: 50%;
|
| 56 |
+
transform: translateY(-50%);
|
| 57 |
+
width: 36px;
|
| 58 |
+
height: 36px;
|
| 59 |
+
padding: 0;
|
| 60 |
+
margin: 0 !important;
|
| 61 |
+
display: flex;
|
| 62 |
+
align-items: center;
|
| 63 |
+
justify-content: center;
|
| 64 |
+
background: transparent;
|
| 65 |
+
border: none;
|
| 66 |
+
cursor: pointer;
|
| 67 |
+
z-index: 5;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.login-box .message {
|
| 71 |
+
display: none;
|
| 72 |
+
padding: 12px;
|
| 73 |
+
margin: 12px 0;
|
| 74 |
+
border-radius: 10px;
|
| 75 |
+
font-size: 13px;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.login-box .message.error {
|
| 79 |
+
display: block;
|
| 80 |
+
color: #fca5a5;
|
| 81 |
+
background: rgba(239,68,68,0.15);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
.login-box .message.success {
|
| 85 |
+
display: block;
|
| 86 |
+
color: #86efac;
|
| 87 |
+
background: rgba(34,197,94,0.15);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.login-box .message.warning {
|
| 91 |
+
display: block;
|
| 92 |
+
color: #fcd34d;
|
| 93 |
+
background: rgba(245,158,11,0.15);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.login-box .loader {
|
| 97 |
+
display: inline-block;
|
| 98 |
+
width: 16px;
|
| 99 |
+
height: 16px;
|
| 100 |
+
border: 2px solid rgba(255,255,255,0.3);
|
| 101 |
+
border-top-color: white;
|
| 102 |
+
border-radius: 50%;
|
| 103 |
+
animation: loginSpin 0.8s linear infinite;
|
| 104 |
+
vertical-align: middle;
|
| 105 |
+
margin-right: 7px;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
@keyframes loginSpin {
|
| 109 |
+
to { transform: rotate(360deg); }
|
| 110 |
+
}
|
| 111 |
+
</style>
|
| 112 |
</head>
|
| 113 |
|
| 114 |
<body class="register-page">
|
|
|
|
| 119 |
|
| 120 |
<h2>Welcome Back</h2>
|
| 121 |
|
| 122 |
+
<p class="sub-title" style="text-align:center;color:#9ca3af;font-size:14px;margin-bottom:25px;">
|
| 123 |
Login to your Cortexa account
|
| 124 |
</p>
|
| 125 |
|
| 126 |
+
<!-- EMAIL -->
|
| 127 |
<input
|
| 128 |
type="email"
|
| 129 |
id="loginEmail"
|
| 130 |
placeholder="Email Address"
|
| 131 |
+
autocomplete="email"
|
| 132 |
required
|
|
|
|
| 133 |
>
|
| 134 |
|
| 135 |
+
<!-- PASSWORD -->
|
| 136 |
<div class="password-wrapper">
|
| 137 |
|
| 138 |
<input
|
| 139 |
type="password"
|
| 140 |
id="loginPassword"
|
| 141 |
placeholder="Password"
|
| 142 |
+
autocomplete="current-password"
|
| 143 |
required
|
| 144 |
>
|
| 145 |
|
|
|
|
| 152 |
|
| 153 |
</div>
|
| 154 |
|
| 155 |
+
<!-- OPTIONS -->
|
| 156 |
+
<div class="form-options"
|
| 157 |
+
style="display:flex;justify-content:space-between;align-items:center;margin:12px 0 18px;font-size:13px;color:#9ca3af;">
|
| 158 |
|
| 159 |
+
<label style="display:flex;align-items:center;gap:8px;cursor:pointer;">
|
| 160 |
<input type="checkbox" id="rememberMe">
|
| 161 |
Remember me
|
| 162 |
</label>
|
| 163 |
|
| 164 |
+
<a href="#" id="forgotPassword"
|
| 165 |
+
style="color:#a855f7;text-decoration:none;">
|
| 166 |
Forgot password?
|
| 167 |
</a>
|
| 168 |
|
| 169 |
</div>
|
| 170 |
|
| 171 |
+
<!-- MESSAGE -->
|
| 172 |
<div id="message" class="message"></div>
|
| 173 |
|
| 174 |
+
<!-- LOGIN BUTTON -->
|
| 175 |
<button type="submit" id="loginBtn">
|
|
|
|
| 176 |
<span id="btnText">Login</span>
|
| 177 |
|
| 178 |
<span id="btnLoader" style="display:none;">
|
| 179 |
<span class="loader"></span>
|
| 180 |
Logging in...
|
| 181 |
</span>
|
|
|
|
| 182 |
</button>
|
| 183 |
|
| 184 |
+
<!-- REGISTER -->
|
| 185 |
+
<p class="register-link"
|
| 186 |
+
style="text-align:center;color:#9ca3af;font-size:14px;margin-top:15px;">
|
| 187 |
+
|
| 188 |
Don't have an account?
|
| 189 |
+
<a href="register.html"
|
| 190 |
+
style="color:#a855f7;text-decoration:none;font-weight:600;">
|
| 191 |
+
Create Account
|
| 192 |
+
</a>
|
| 193 |
+
|
| 194 |
</p>
|
| 195 |
|
| 196 |
</form>
|
| 197 |
|
| 198 |
</div>
|
| 199 |
|
|
|
|
| 200 |
<script>
|
| 201 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 202 |
|
| 203 |
+
const form = document.getElementById('loginForm');
|
| 204 |
+
const emailInput = document.getElementById('loginEmail');
|
| 205 |
+
const passwordInput = document.getElementById('loginPassword');
|
| 206 |
+
const rememberMe = document.getElementById('rememberMe');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
+
const loginBtn = document.getElementById('loginBtn');
|
| 209 |
+
const btnText = document.getElementById('btnText');
|
| 210 |
+
const btnLoader = document.getElementById('btnLoader');
|
| 211 |
+
const message = document.getElementById('message');
|
| 212 |
|
| 213 |
+
let isLoggingIn = false;
|
|
|
|
| 214 |
|
| 215 |
+
// SHOW MESSAGE
|
| 216 |
+
function showMessage(text, type) {
|
| 217 |
+
message.textContent = text;
|
| 218 |
+
message.className = 'message ' + type;
|
| 219 |
+
message.style.display = 'block';
|
| 220 |
}
|
| 221 |
|
| 222 |
+
// HIDE MESSAGE
|
| 223 |
+
function hideMessage() {
|
| 224 |
+
message.textContent = '';
|
| 225 |
+
message.className = 'message';
|
| 226 |
+
message.style.display = 'none';
|
|
|
|
|
|
|
| 227 |
}
|
| 228 |
|
| 229 |
+
// PASSWORD VISIBILITY
|
| 230 |
+
document.getElementById('togglePassword').addEventListener('click', function() {
|
| 231 |
|
| 232 |
+
const visible = passwordInput.type === 'password';
|
|
|
|
| 233 |
|
| 234 |
+
passwordInput.type = visible ? 'text' : 'password';
|
| 235 |
+
this.textContent = visible ? '🙈' : '👁️';
|
| 236 |
|
| 237 |
+
this.setAttribute(
|
| 238 |
+
'aria-label',
|
| 239 |
+
visible ? 'Hide password' : 'Show password'
|
| 240 |
+
);
|
| 241 |
+
});
|
| 242 |
|
| 243 |
+
// FORGOT PASSWORD
|
| 244 |
+
document.getElementById('forgotPassword').addEventListener('click', function(e) {
|
| 245 |
+
e.preventDefault();
|
| 246 |
+
showMessage('Password reset feature coming soon!', 'warning');
|
| 247 |
+
});
|
| 248 |
|
| 249 |
+
// REMEMBERED EMAIL
|
| 250 |
try {
|
| 251 |
+
const savedEmail = localStorage.getItem('savedEmail');
|
| 252 |
|
| 253 |
+
if (savedEmail && localStorage.getItem('rememberMe') === 'true') {
|
| 254 |
+
emailInput.value = savedEmail;
|
| 255 |
+
rememberMe.checked = true;
|
| 256 |
+
}
|
| 257 |
+
} catch (error) {
|
| 258 |
+
console.warn('Local storage unavailable:', error);
|
| 259 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
+
// LOGIN FORM SUBMISSION
|
| 262 |
+
form.addEventListener('submit', async function(e) {
|
| 263 |
|
| 264 |
+
e.preventDefault();
|
| 265 |
|
| 266 |
+
if (isLoggingIn) return;
|
| 267 |
|
| 268 |
+
hideMessage();
|
| 269 |
|
| 270 |
+
const email = emailInput.value.trim();
|
| 271 |
+
const password = passwordInput.value;
|
| 272 |
|
| 273 |
+
if (!email || !password) {
|
| 274 |
+
showMessage('Please enter your email and password.', 'error');
|
| 275 |
return;
|
|
|
|
| 276 |
}
|
| 277 |
|
| 278 |
+
if (password.length < 8) {
|
| 279 |
+
showMessage('Password must be at least 8 characters.', 'error');
|
|
|
|
|
|
|
|
|
|
| 280 |
return;
|
|
|
|
| 281 |
}
|
| 282 |
|
| 283 |
+
// START LOADING
|
| 284 |
+
isLoggingIn = true;
|
| 285 |
+
loginBtn.disabled = true;
|
| 286 |
+
btnText.style.display = 'none';
|
| 287 |
+
btnLoader.style.display = 'inline-flex';
|
| 288 |
+
|
| 289 |
+
try {
|
| 290 |
+
|
| 291 |
+
// CONNECT TO FLASK
|
| 292 |
+
const response = await fetch('/api/login', {
|
| 293 |
+
method: 'POST',
|
| 294 |
+
headers: {
|
| 295 |
+
'Content-Type': 'application/json',
|
| 296 |
+
'Accept': 'application/json'
|
| 297 |
+
},
|
| 298 |
+
body: JSON.stringify({
|
| 299 |
+
email: email,
|
| 300 |
+
password: password
|
| 301 |
+
})
|
| 302 |
+
});
|
| 303 |
+
|
| 304 |
+
// READ RESPONSE
|
| 305 |
+
const data = await response.json();
|
| 306 |
+
|
| 307 |
+
if (!response.ok) {
|
| 308 |
+
|
| 309 |
+
const errorMsg = data.error || data.message || 'Invalid email or password.';
|
| 310 |
+
|
| 311 |
+
if (errorMsg.toLowerCase().includes('verify your email')) {
|
| 312 |
+
showMessage('Please verify your email before logging in.', 'warning');
|
| 313 |
+
}
|
| 314 |
+
else if (errorMsg.toLowerCase().includes('verify your phone')) {
|
| 315 |
+
showMessage('Please verify your phone number before logging in.', 'warning');
|
| 316 |
+
}
|
| 317 |
+
else {
|
| 318 |
+
showMessage(errorMsg, 'error');
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
return;
|
| 322 |
+
}
|
| 323 |
|
| 324 |
+
// GET TOKEN
|
| 325 |
+
const token = data.access_token || data.accessToken;
|
| 326 |
|
| 327 |
+
if (!token || !data.user) {
|
| 328 |
+
showMessage('Server response is missing the login token or user information.', 'error');
|
| 329 |
+
return;
|
| 330 |
+
}
|
| 331 |
|
| 332 |
+
// SAVE LOGIN DATA
|
| 333 |
+
localStorage.setItem('access_token', token);
|
| 334 |
|
| 335 |
+
// Keep both keys for compatibility with existing pages
|
| 336 |
+
localStorage.setItem('accessToken', token);
|
| 337 |
|
| 338 |
+
localStorage.setItem('currentUser', JSON.stringify(data.user));
|
| 339 |
+
localStorage.setItem('isLoggedIn', 'true');
|
| 340 |
|
| 341 |
+
// REMEMBER ME
|
| 342 |
+
if (rememberMe.checked) {
|
| 343 |
+
localStorage.setItem('rememberMe', 'true');
|
| 344 |
+
localStorage.setItem('savedEmail', email);
|
| 345 |
+
} else {
|
| 346 |
+
localStorage.removeItem('rememberMe');
|
| 347 |
+
localStorage.removeItem('savedEmail');
|
| 348 |
+
}
|
| 349 |
|
| 350 |
+
showMessage('Login successful! Redirecting...', 'success');
|
| 351 |
|
| 352 |
+
// REDIRECT
|
| 353 |
+
setTimeout(function() {
|
| 354 |
+
window.location.href = 'dashboard.html';
|
| 355 |
+
}, 1200);
|
| 356 |
|
| 357 |
}
|
| 358 |
+
catch (error) {
|
| 359 |
|
| 360 |
+
console.error('Login error:', error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
|
| 362 |
+
showMessage(
|
| 363 |
+
'Cannot connect to the server. Make sure your Flask server is running.',
|
| 364 |
+
'error'
|
| 365 |
+
);
|
| 366 |
|
| 367 |
+
}
|
| 368 |
+
finally {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
|
| 370 |
+
isLoggingIn = false;
|
| 371 |
+
loginBtn.disabled = false;
|
| 372 |
|
| 373 |
+
btnText.style.display = 'inline';
|
| 374 |
+
btnLoader.style.display = 'none';
|
| 375 |
|
| 376 |
+
}
|
| 377 |
|
| 378 |
+
});
|
| 379 |
|
| 380 |
+
// REGISTRATION MESSAGE
|
| 381 |
+
const params = new URLSearchParams(window.location.search);
|
| 382 |
+
const registrationMessage = params.get('message');
|
| 383 |
|
| 384 |
if (registrationMessage) {
|
|
|
|
| 385 |
showMessage(registrationMessage, 'success');
|
|
|
|
| 386 |
}
|
| 387 |
|
| 388 |
+
console.log('Cortexa login initialized successfully.');
|
| 389 |
|
| 390 |
});
|
|
|
|
| 391 |
</script>
|
| 392 |
|
| 393 |
</body>
|