255 lines
7.9 KiB
HTML
255 lines
7.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<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;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="login-card">
|
|
<div class="login-header">
|
|
<h1>Location Map Viewer</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>
|
|
|
|
<button type="submit" class="login-button" id="login-button">
|
|
Sign In
|
|
</button>
|
|
</form>
|
|
|
|
<div class="login-footer">
|
|
<p>Access is restricted to authorized users only.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Handle login form submission
|
|
document.getElementById('login-form').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const email = document.getElementById('email').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 }),
|
|
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);
|
|
</script>
|
|
</body>
|
|
</html>
|