530 lines
17 KiB
HTML
530 lines
17 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
|
<meta name="description" content="Login to Map by BNKops - Interactive canvassing web-app & viewer">
|
|
<title>Login - Map by BNKops</title>
|
|
|
|
<!-- Custom CSS -->
|
|
<link rel="stylesheet" href="css/style.css">
|
|
<style>
|
|
.login-container {
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background-color: var(--light-color);
|
|
padding: 20px;
|
|
}
|
|
|
|
.login-card {
|
|
background-color: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
|
|
padding: 40px;
|
|
width: 100%;
|
|
max-width: 400px;
|
|
}
|
|
|
|
.login-header {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.login-header h1 {
|
|
color: var(--dark-color);
|
|
font-size: 28px;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.login-header p {
|
|
color: var(--secondary-color);
|
|
font-size: 16px;
|
|
}
|
|
|
|
.login-form {
|
|
margin-top: 30px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
font-weight: 500;
|
|
color: var(--dark-color);
|
|
}
|
|
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 12px 16px;
|
|
border: 1px solid #ddd;
|
|
border-radius: var(--border-radius);
|
|
font-size: 16px;
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: var(--primary-color);
|
|
box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.1);
|
|
}
|
|
|
|
.login-button {
|
|
width: 100%;
|
|
padding: 12px 16px;
|
|
background-color: var(--primary-color);
|
|
color: white;
|
|
border: none;
|
|
border-radius: var(--border-radius);
|
|
font-size: 16px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.login-button:hover {
|
|
background-color: #2471a3;
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
|
|
}
|
|
|
|
.login-button:active {
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.login-button:disabled {
|
|
background-color: var(--secondary-color);
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.error-message {
|
|
background-color: #fee;
|
|
color: var(--danger-color);
|
|
padding: 12px;
|
|
border-radius: var(--border-radius);
|
|
margin-bottom: 20px;
|
|
font-size: 14px;
|
|
display: none;
|
|
}
|
|
|
|
.error-message.show {
|
|
display: block;
|
|
}
|
|
|
|
.success-message {
|
|
background-color: #efe;
|
|
color: var(--success-color);
|
|
padding: 12px;
|
|
border-radius: var(--border-radius);
|
|
margin-bottom: 20px;
|
|
font-size: 14px;
|
|
display: none;
|
|
}
|
|
|
|
.success-message.show {
|
|
display: block;
|
|
}
|
|
|
|
.login-footer {
|
|
margin-top: 30px;
|
|
text-align: center;
|
|
color: var(--secondary-color);
|
|
font-size: 14px;
|
|
}
|
|
|
|
.password-recovery {
|
|
text-align: center;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.password-recovery a {
|
|
color: var(--primary-color);
|
|
text-decoration: none;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.password-recovery a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
/* Custom Modal Styles */
|
|
.modal-overlay {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
display: none;
|
|
align-items: center;
|
|
justify-content: center;
|
|
z-index: 1000;
|
|
backdrop-filter: blur(2px);
|
|
}
|
|
|
|
.modal-overlay.show {
|
|
display: flex;
|
|
}
|
|
|
|
.modal-content {
|
|
background: white;
|
|
border-radius: 8px;
|
|
padding: 30px;
|
|
width: 90%;
|
|
max-width: 400px;
|
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
|
|
animation: modalSlideIn 0.3s ease;
|
|
}
|
|
|
|
@keyframes modalSlideIn {
|
|
from {
|
|
transform: translateY(-50px);
|
|
opacity: 0;
|
|
}
|
|
to {
|
|
transform: translateY(0);
|
|
opacity: 1;
|
|
}
|
|
}
|
|
|
|
.modal-header {
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.modal-header h3 {
|
|
margin: 0;
|
|
color: var(--dark-color);
|
|
font-size: 20px;
|
|
}
|
|
|
|
.modal-header p {
|
|
margin: 8px 0 0 0;
|
|
color: var(--secondary-color);
|
|
font-size: 14px;
|
|
}
|
|
|
|
.modal-form {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.modal-form .form-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.modal-form label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
font-weight: 500;
|
|
color: var(--dark-color);
|
|
}
|
|
|
|
.modal-form input[type="email"] {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid var(--light-color);
|
|
border-radius: var(--border-radius);
|
|
font-size: 14px;
|
|
transition: border-color 0.3s ease;
|
|
}
|
|
|
|
.modal-form input[type="email"]:focus {
|
|
outline: none;
|
|
border-color: var(--primary-color);
|
|
}
|
|
|
|
.modal-buttons {
|
|
display: flex;
|
|
gap: 10px;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.modal-button {
|
|
padding: 10px 20px;
|
|
border: none;
|
|
border-radius: var(--border-radius);
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.modal-button.primary {
|
|
background-color: var(--primary-color);
|
|
color: white;
|
|
}
|
|
|
|
.modal-button.primary:hover {
|
|
background-color: var(--primary-hover);
|
|
}
|
|
|
|
.modal-button.secondary {
|
|
background-color: var(--light-color);
|
|
color: var(--dark-color);
|
|
}
|
|
|
|
.modal-button.secondary:hover {
|
|
background-color: var(--secondary-color);
|
|
}
|
|
|
|
.modal-button:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="login-card">
|
|
<div class="login-header">
|
|
<h1>BNKops Map</h1>
|
|
<p>Please sign in to continue</p>
|
|
</div>
|
|
|
|
<div id="error-message" class="error-message"></div>
|
|
<div id="success-message" class="success-message"></div>
|
|
|
|
<form id="login-form" class="login-form">
|
|
<div class="form-group">
|
|
<label for="email">Email Address</label>
|
|
<input
|
|
type="email"
|
|
id="email"
|
|
name="email"
|
|
placeholder="Enter your email address"
|
|
required
|
|
autocomplete="email"
|
|
autofocus
|
|
>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input
|
|
type="password"
|
|
id="password"
|
|
name="password"
|
|
placeholder="Enter your password"
|
|
required
|
|
autocomplete="current-password"
|
|
>
|
|
</div>
|
|
|
|
<button type="submit" class="login-button" id="login-button">
|
|
Sign In
|
|
</button>
|
|
</form>
|
|
|
|
<div class="password-recovery">
|
|
<a href="#" id="forgot-password-link">Forgot your password?</a>
|
|
</div>
|
|
|
|
<div class="login-footer">
|
|
<p>Access is restricted to authorized users only. Please contact your system administrator for login details.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Password Recovery Modal -->
|
|
<div class="modal-overlay" id="password-recovery-modal">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h3>Password Recovery</h3>
|
|
<p>Enter your email address to receive your password</p>
|
|
</div>
|
|
<form class="modal-form" id="password-recovery-form">
|
|
<div class="form-group">
|
|
<label for="recovery-email">Email Address</label>
|
|
<input
|
|
type="email"
|
|
id="recovery-email"
|
|
name="recovery-email"
|
|
placeholder="Enter your email address"
|
|
required
|
|
autocomplete="email"
|
|
>
|
|
</div>
|
|
<div class="modal-buttons">
|
|
<button type="button" class="modal-button secondary" id="cancel-recovery">Cancel</button>
|
|
<button type="submit" class="modal-button primary" id="send-recovery">Send Password</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Handle login form submission
|
|
document.getElementById('login-form').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const email = document.getElementById('email').value;
|
|
const password = document.getElementById('password').value;
|
|
const button = document.getElementById('login-button');
|
|
const errorMessage = document.getElementById('error-message');
|
|
const successMessage = document.getElementById('success-message');
|
|
|
|
// Clear previous messages
|
|
errorMessage.classList.remove('show');
|
|
successMessage.classList.remove('show');
|
|
|
|
// Disable button and show loading state
|
|
button.disabled = true;
|
|
button.textContent = 'Signing in...';
|
|
|
|
try {
|
|
const response = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ email, password }),
|
|
credentials: 'include'
|
|
});
|
|
|
|
// Get response text first
|
|
const responseText = await response.text();
|
|
let data;
|
|
|
|
try {
|
|
// Try to parse as JSON
|
|
data = JSON.parse(responseText);
|
|
} catch (parseError) {
|
|
// If not JSON, handle as text
|
|
console.error('Response is not JSON:', responseText);
|
|
if (response.status === 429) {
|
|
throw new Error('Too many login attempts. Please try again in a few minutes.');
|
|
} else {
|
|
throw new Error(responseText || `Server error (${response.status})`);
|
|
}
|
|
}
|
|
|
|
if (response.ok && data.success) {
|
|
console.log('Login successful, redirecting...');
|
|
successMessage.textContent = 'Login successful! Redirecting...';
|
|
successMessage.classList.add('show');
|
|
|
|
setTimeout(() => {
|
|
window.location.replace('/');
|
|
}, 500);
|
|
} else {
|
|
throw new Error(data.error || 'Login failed');
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
errorMessage.textContent = error.message;
|
|
errorMessage.classList.add('show');
|
|
button.disabled = false;
|
|
button.textContent = 'Sign In';
|
|
}
|
|
});
|
|
|
|
// Check if already logged in
|
|
fetch('/api/auth/check')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.authenticated) {
|
|
window.location.href = '/';
|
|
}
|
|
})
|
|
.catch(console.error);
|
|
|
|
// Modal elements
|
|
const modal = document.getElementById('password-recovery-modal');
|
|
const forgotPasswordLink = document.getElementById('forgot-password-link');
|
|
const cancelButton = document.getElementById('cancel-recovery');
|
|
const recoveryForm = document.getElementById('password-recovery-form');
|
|
const recoveryEmailInput = document.getElementById('recovery-email');
|
|
const sendButton = document.getElementById('send-recovery');
|
|
|
|
// Show modal when "Forgot password?" is clicked
|
|
forgotPasswordLink.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
modal.classList.add('show');
|
|
recoveryEmailInput.focus();
|
|
});
|
|
|
|
// Hide modal when cancel is clicked
|
|
cancelButton.addEventListener('click', () => {
|
|
modal.classList.remove('show');
|
|
recoveryForm.reset();
|
|
});
|
|
|
|
// Hide modal when clicking outside
|
|
modal.addEventListener('click', (e) => {
|
|
if (e.target === modal) {
|
|
modal.classList.remove('show');
|
|
recoveryForm.reset();
|
|
}
|
|
});
|
|
|
|
// Handle password recovery form submission
|
|
recoveryForm.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const email = recoveryEmailInput.value.trim();
|
|
if (!email) return;
|
|
|
|
const errorMessage = document.getElementById('error-message');
|
|
const successMessage = document.getElementById('success-message');
|
|
|
|
// Clear previous messages
|
|
errorMessage.classList.remove('show');
|
|
successMessage.classList.remove('show');
|
|
|
|
// Disable form during submission
|
|
sendButton.disabled = true;
|
|
sendButton.textContent = 'Sending...';
|
|
|
|
try {
|
|
const response = await fetch('/api/auth/recover-password', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ email })
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
successMessage.textContent = data.message;
|
|
successMessage.classList.add('show');
|
|
|
|
// Close modal on success
|
|
modal.classList.remove('show');
|
|
recoveryForm.reset();
|
|
} else {
|
|
errorMessage.textContent = data.error || 'Failed to process request';
|
|
errorMessage.classList.add('show');
|
|
}
|
|
} catch (error) {
|
|
console.error('Password recovery error:', error);
|
|
errorMessage.textContent = 'Failed to send password recovery email';
|
|
errorMessage.classList.add('show');
|
|
} finally {
|
|
// Re-enable form
|
|
sendButton.disabled = false;
|
|
sendButton.textContent = 'Send Password';
|
|
}
|
|
});
|
|
|
|
// Handle Escape key to close modal
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape' && modal.classList.contains('show')) {
|
|
modal.classList.remove('show');
|
|
recoveryForm.reset();
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<!-- Cache Management -->
|
|
<script src="js/cache-manager.js"></script>
|
|
</body>
|
|
</html>
|