eK

ekTextAI

Account recovery

Reset Password

Enter your account email to receive a secure link

We’ll send a one‑time reset link

Or

Remembered? Sign in

New user? Create account

const loadingDiv = document.getElementById('loading'); const resendButton = document.getElementById('resend-button'); const countdownSpan = document.getElementById('countdown'); const sentEmailSpan = document.getElementById('sent-email'); const tryDifferentEmailBtn = document.getElementById('try-different-email'); let countdownTimer; let countdownValue = 60; // Show message function function showMessage(text, type = 'info') { messageDiv.className = `mt-4 p-4 rounded-lg ${type === 'error' ? 'bg-red-50 text-red-700 border border-red-200' : type === 'success' ? 'bg-green-50 text-green-700 border border-green-200' : 'bg-blue-50 text-blue-700 border border-blue-200'}`; messageDiv.textContent = text; messageDiv.classList.remove('hidden'); } // Hide message function function hideMessage() { messageDiv.classList.add('hidden'); } // Show loading function showLoading() { loadingDiv.classList.remove('hidden'); } // Hide loading function hideLoading() { loadingDiv.classList.add('hidden'); } // Start countdown timer function startCountdown() { countdownValue = 60; resendButton.disabled = true; countdownTimer = setInterval(() => { countdownValue--; countdownSpan.textContent = countdownValue; if (countdownValue <= 0) { clearInterval(countdownTimer); resendButton.disabled = false; document.getElementById('resend-text').textContent = 'Resend Email'; } }, 1000); } // Handle password reset form submission resetForm.addEventListener('submit', async (e) => { e.preventDefault(); const email = document.getElementById('email').value.trim(); if (!email) { showMessage('Please enter your email address.', 'error'); return; } // Email format validation const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(email)) { showMessage('Please enter a valid email address.', 'error'); return; } hideMessage(); showLoading(); resetButton.disabled = true; resetButton.textContent = 'Sending...'; try { const response = await fetch(`${API_BASE}/auth/forgot`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email }), }); const data = await response.json(); if (response.ok) { // Show success message sentEmailSpan.textContent = email; emailForm.classList.add('hidden'); successMessage.classList.remove('hidden'); startCountdown(); } else { showMessage(data.message || 'Failed to send reset email. Please try again.', 'error'); } } catch (error) { console.error('Password reset error:', error); showMessage('Network error. Please check your connection and try again.', 'error'); } finally { hideLoading(); resetButton.disabled = false; resetButton.textContent = 'Send Reset Link'; } }); // Handle resend email resendButton.addEventListener('click', async () => { const email = sentEmailSpan.textContent; resendButton.disabled = true; resendButton.textContent = 'Sending...'; try { const response = await fetch(`${API_BASE}/auth/forgot`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email }), }); if (response.ok) { startCountdown(); // Could show a brief success message here } } catch (error) { console.error('Resend error:', error); } }); // Handle try different email tryDifferentEmailBtn.addEventListener('click', () => { // Clear countdown if (countdownTimer) { clearInterval(countdownTimer); } // Reset form resetForm.reset(); hideMessage(); // Show email form again successMessage.classList.add('hidden'); emailForm.classList.remove('hidden'); }); // Email input validation document.getElementById('email').addEventListener('input', (e) => { const email = e.target.value; const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (email && !emailRegex.test(email)) { e.target.style.borderColor = '#ef4444'; } else { e.target.style.borderColor = '#d1d5db'; } }); // Check if user is already logged in document.addEventListener('DOMContentLoaded', () => { const jwt = localStorage.getItem('jwt'); if (jwt) { // User is already logged in, redirect to dashboard window.location.href = '/dashboard.html'; } // Check for URL parameters (if coming from a reset link) const urlParams = new URLSearchParams(window.location.search); const token = urlParams.get('token'); if (token) { // This is a password reset confirmation page // You might want to create a separate page for this // For now, we'll redirect to a reset confirmation page if it exists window.location.href = `/reset-password.html?token=${token}`; } }); // Animate step cards on load document.addEventListener('DOMContentLoaded', () => { const stepCards = document.querySelectorAll('.step-card'); stepCards.forEach((card, index) => { setTimeout(() => { card.style.opacity = '0'; card.style.transform = 'translateX(-20px)'; card.style.transition = 'all 0.6s ease'; setTimeout(() => { card.style.opacity = '1'; card.style.transform = 'translateX(0)'; }, 100); }, index * 200); }); });