New login view
This commit is contained in:
@@ -66,6 +66,21 @@ body {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* User info in header */
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding: 0 15px;
|
||||
border-right: 1px solid rgba(255,255,255,0.2);
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
.user-email {
|
||||
font-size: 14px;
|
||||
color: rgba(255,255,255,0.9);
|
||||
}
|
||||
|
||||
/* Map container */
|
||||
#map-container {
|
||||
flex: 1;
|
||||
@@ -555,6 +570,11 @@ body {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Hide user info on mobile to save space */
|
||||
.user-info {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px;
|
||||
min-width: 40px;
|
||||
|
||||
@@ -14,11 +14,13 @@ let markers = [];
|
||||
let userLocationMarker = null;
|
||||
let isAddingLocation = false;
|
||||
let refreshInterval = null;
|
||||
let currentEditingLocation = null; // Add this line
|
||||
let currentEditingLocation = null;
|
||||
let currentUser = null; // Add current user state
|
||||
|
||||
// Initialize application when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initializeMap();
|
||||
checkAuthentication(); // Add authentication check
|
||||
loadLocations();
|
||||
setupEventListeners();
|
||||
checkConfiguration();
|
||||
@@ -222,6 +224,68 @@ function setupGeoFieldSync() {
|
||||
});
|
||||
}
|
||||
|
||||
// Check authentication and display user info
|
||||
async function checkAuthentication() {
|
||||
try {
|
||||
const response = await fetch('/api/auth/check');
|
||||
const data = await response.json();
|
||||
|
||||
if (data.authenticated && data.user) {
|
||||
currentUser = data.user;
|
||||
displayUserInfo();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to check authentication:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Display user info in header
|
||||
function displayUserInfo() {
|
||||
const headerActions = document.querySelector('.header-actions');
|
||||
|
||||
// Create user info element
|
||||
const userInfo = document.createElement('div');
|
||||
userInfo.className = 'user-info';
|
||||
userInfo.innerHTML = `
|
||||
<span class="user-email">${escapeHtml(currentUser.email)}</span>
|
||||
<button id="logout-btn" class="btn btn-secondary btn-sm" title="Sign out">
|
||||
🚪 Logout
|
||||
</button>
|
||||
`;
|
||||
|
||||
// Insert before the location count
|
||||
const locationCount = document.getElementById('location-count');
|
||||
headerActions.insertBefore(userInfo, locationCount);
|
||||
|
||||
// Add logout event listener
|
||||
document.getElementById('logout-btn').addEventListener('click', handleLogout);
|
||||
}
|
||||
|
||||
// Handle logout
|
||||
async function handleLogout() {
|
||||
if (!confirm('Are you sure you want to logout?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/auth/logout', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
window.location.href = '/login.html';
|
||||
} else {
|
||||
showStatus('Logout failed. Please try again.', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Logout error:', error);
|
||||
showStatus('Logout failed. Please try again.', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Check API configuration
|
||||
async function checkConfiguration() {
|
||||
try {
|
||||
|
||||
240
nocodb-map-viewer/app/public/login.html
Normal file
240
nocodb-map-viewer/app/public/login.html
Normal file
@@ -0,0 +1,240 @@
|
||||
<!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 NocoDB Map Viewer">
|
||||
<title>Login - NocoDB Map Viewer</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 })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok && data.success) {
|
||||
successMessage.textContent = 'Login successful! Redirecting...';
|
||||
successMessage.classList.add('show');
|
||||
|
||||
// Redirect to main app after short delay
|
||||
setTimeout(() => {
|
||||
window.location.href = '/';
|
||||
}, 1000);
|
||||
} else {
|
||||
errorMessage.textContent = data.error || 'Invalid email address';
|
||||
errorMessage.classList.add('show');
|
||||
button.disabled = false;
|
||||
button.textContent = 'Sign In';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
errorMessage.textContent = 'An error occurred. Please try again.';
|
||||
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>
|
||||
Reference in New Issue
Block a user