|
@@ -35,6 +35,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
localStorage.removeItem('userData');
|
|
localStorage.removeItem('userData');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ const forgotPasswordLink = document.getElementById('forgotPasswordLink');
|
|
|
|
|
+ if (forgotPasswordLink) {
|
|
|
|
|
+ forgotPasswordLink.addEventListener('click', handleForgotPassword);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
function switchTab(tab) {
|
|
function switchTab(tab) {
|
|
@@ -444,4 +449,52 @@ function hideEditProfileForm() {
|
|
|
// Clear form and messages
|
|
// Clear form and messages
|
|
|
document.getElementById('editProfileForm').reset();
|
|
document.getElementById('editProfileForm').reset();
|
|
|
clearEditProfileMessages();
|
|
clearEditProfileMessages();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function handleForgotPassword(e) {
|
|
|
|
|
+ e.preventDefault();
|
|
|
|
|
+
|
|
|
|
|
+ const username = document.getElementById('loginUsername').value.trim();
|
|
|
|
|
+
|
|
|
|
|
+ if (!username) {
|
|
|
|
|
+ showMessage('loginMessage', 'Please enter your username above and then click "Forgot password" again.', 'error');
|
|
|
|
|
+ document.getElementById('loginUsername').focus();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ clearMessages();
|
|
|
|
|
+
|
|
|
|
|
+ const link = document.getElementById('forgotPasswordLink');
|
|
|
|
|
+ const originalText = link.textContent;
|
|
|
|
|
+ link.textContent = 'Sending email...';
|
|
|
|
|
+ link.style.pointerEvents = 'none';
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await fetch(`${API_BASE_URL}/forgot-password?username=${encodeURIComponent(username)}`, {
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (response.ok) {
|
|
|
|
|
+ showMessage('loginMessage', 'Password reset email sent! Please check your inbox.', 'success');
|
|
|
|
|
+ document.getElementById('loginUsername').value = '';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const errorData = await response.json();
|
|
|
|
|
+ const errorMessage = errorData.message || 'Failed to send reset email. Please try again.';
|
|
|
|
|
+ showMessage('loginMessage', errorMessage, 'error');
|
|
|
|
|
+ } catch (parseError) {
|
|
|
|
|
+ const errorText = await response.text();
|
|
|
|
|
+ showMessage('loginMessage', errorText || 'Failed to send reset email. Please try again.', 'error');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Forgot password error:', error);
|
|
|
|
|
+ showMessage('loginMessage', 'Network error. Please check if the auth service is running.', 'error');
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ link.textContent = originalText;
|
|
|
|
|
+ link.style.pointerEvents = 'auto';
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|