mirror of
https://github.com/sassanix/Warracker.git
synced 2026-01-24 06:58:34 -06:00
244 lines
8.5 KiB
HTML
244 lines
8.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Warracker - Reset Password</title>
|
|
<!-- Favicons -->
|
|
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
|
|
<link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
|
|
<link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
|
|
<link rel="stylesheet" href="style.css">
|
|
<script src="theme-loader.js"></script> <!-- Apply theme early -->
|
|
<!-- Font Awesome for icons -->
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<style>
|
|
.auth-container {
|
|
max-width: 400px;
|
|
margin: 50px auto;
|
|
padding: 30px;
|
|
background-color: var(--card-bg);
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.auth-title {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
color: var(--text-color);
|
|
}
|
|
|
|
.auth-form .form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.auth-links {
|
|
margin-top: 20px;
|
|
text-align: center;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.auth-links a {
|
|
color: var(--primary-color);
|
|
text-decoration: none;
|
|
margin: 0 10px;
|
|
}
|
|
|
|
.auth-links a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.auth-message {
|
|
margin-top: 20px;
|
|
padding: 10px;
|
|
border-radius: 4px;
|
|
text-align: center;
|
|
display: none;
|
|
}
|
|
|
|
.auth-message.error {
|
|
background-color: rgba(244, 67, 54, 0.1);
|
|
color: #f44336;
|
|
border: 1px solid rgba(244, 67, 54, 0.3);
|
|
}
|
|
|
|
.auth-message.success {
|
|
background-color: rgba(76, 175, 80, 0.1);
|
|
color: #4caf50;
|
|
border: 1px solid rgba(76, 175, 80, 0.3);
|
|
}
|
|
|
|
.btn-block {
|
|
width: 100%;
|
|
}
|
|
|
|
.auth-info {
|
|
margin-bottom: 20px;
|
|
color: var(--text-muted);
|
|
text-align: center;
|
|
font-size: 0.9em;
|
|
line-height: 1.5;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Header -->
|
|
<header>
|
|
<div class="container">
|
|
<div class="app-title">
|
|
<i class="fas fa-shield-alt"></i>
|
|
<h1>Warracker</h1>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Main Content -->
|
|
<div class="container">
|
|
<div class="auth-container">
|
|
<h2 class="auth-title">Reset Your Password</h2>
|
|
|
|
<p class="auth-info">
|
|
Enter your email address below and we'll send you a link to reset your password.
|
|
</p>
|
|
|
|
<div id="authMessage" class="auth-message"></div>
|
|
|
|
<form id="resetRequestForm" class="auth-form">
|
|
<div class="form-group">
|
|
<label for="email">Email Address</label>
|
|
<input type="email" id="email" name="email" class="form-control" required>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary btn-block">
|
|
<i class="fas fa-paper-plane"></i> Send Reset Link
|
|
</button>
|
|
</form>
|
|
|
|
<div class="auth-links">
|
|
<a href="login.html">Back to Login</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Check if user is already logged in
|
|
const token = localStorage.getItem('auth_token');
|
|
if (token) {
|
|
// Redirect to home page if already logged in
|
|
window.location.href = 'index.html';
|
|
return;
|
|
}
|
|
|
|
// Handle form submission
|
|
const resetRequestForm = document.getElementById('resetRequestForm');
|
|
const authMessage = document.getElementById('authMessage');
|
|
|
|
resetRequestForm.addEventListener('submit', async function(e) {
|
|
e.preventDefault();
|
|
|
|
const email = document.getElementById('email').value;
|
|
|
|
// Basic validation
|
|
if (!email) {
|
|
showMessage('Please enter your email address', 'error');
|
|
return;
|
|
}
|
|
|
|
// Validate email format
|
|
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
if (!emailRegex.test(email)) {
|
|
showMessage('Please enter a valid email address', 'error');
|
|
return;
|
|
}
|
|
|
|
// Get the submit button element
|
|
const submitBtn = resetRequestForm.querySelector('button[type="submit"]');
|
|
let originalBtnText = ''; // Initialize outside
|
|
|
|
if (!submitBtn) {
|
|
console.error('Submit button not found');
|
|
showMessage('An unexpected error occurred. Please try again.', 'error');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// Show loading state
|
|
originalBtnText = submitBtn.innerHTML; // Assign original text here
|
|
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Sending Request...';
|
|
submitBtn.disabled = true;
|
|
|
|
// Make API request
|
|
const response = await fetch('/api/auth/password/reset-request', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
email
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.message || 'Password reset request failed');
|
|
}
|
|
|
|
// Show success message
|
|
showMessage('Password reset instructions have been sent to your email. Please check your inbox.', 'success');
|
|
|
|
// Clear form
|
|
resetRequestForm.reset();
|
|
|
|
} catch (error) {
|
|
console.error('Password reset request error:', error);
|
|
showMessage(error.message || 'Password reset request failed. Please try again.', 'error');
|
|
} finally {
|
|
// Reset button only if it exists
|
|
if (submitBtn) {
|
|
submitBtn.innerHTML = originalBtnText;
|
|
submitBtn.disabled = false;
|
|
}
|
|
}
|
|
});
|
|
|
|
function showMessage(message, type) {
|
|
authMessage.textContent = message;
|
|
authMessage.className = 'auth-message';
|
|
authMessage.classList.add(type);
|
|
authMessage.style.display = 'block';
|
|
}
|
|
|
|
// Check for dark mode preference
|
|
const darkModeEnabled = localStorage.getItem('darkMode') === 'enabled';
|
|
if (darkModeEnabled) {
|
|
document.body.classList.add('dark-mode');
|
|
}
|
|
});
|
|
|
|
// Theme initialization
|
|
function setTheme(isDark) {
|
|
document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
|
|
}
|
|
|
|
function initializeTheme() {
|
|
// Check for saved theme preference
|
|
const savedTheme = localStorage.getItem('darkMode');
|
|
|
|
if (savedTheme !== null) {
|
|
// Use saved preference
|
|
setTheme(savedTheme === 'true');
|
|
} else {
|
|
// Use system preference as fallback
|
|
const prefersDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
setTheme(prefersDarkMode);
|
|
}
|
|
}
|
|
|
|
// Initialize theme when page loads
|
|
document.addEventListener('DOMContentLoaded', initializeTheme);
|
|
</script>
|
|
</body>
|
|
</html>
|