404 lines
13 KiB
HTML
404 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>PRISM - Construction Job Management</title>
|
|
<style>
|
|
:root {
|
|
--gruvbox-bg0: #282828;
|
|
--gruvbox-bg1: #3c3836;
|
|
--gruvbox-bg2: #504945;
|
|
--gruvbox-bg3: #665c54;
|
|
--gruvbox-fg0: #fbf1c7;
|
|
--gruvbox-fg1: #ebdbb2;
|
|
--gruvbox-fg2: #d5c4a1;
|
|
--gruvbox-orange: #fe8019;
|
|
--gruvbox-green: #b8bb26;
|
|
--gruvbox-blue: #83a598;
|
|
--gruvbox-purple: #d3869b;
|
|
--gruvbox-red: #fb4934;
|
|
--gruvbox-yellow: #fabd2f;
|
|
}
|
|
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'SF Pro Display', 'Segoe UI', system-ui, -apple-system, sans-serif;
|
|
background: linear-gradient(135deg, var(--gruvbox-bg0) 0%, var(--gruvbox-bg2) 50%, var(--gruvbox-bg1) 100%);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: var(--gruvbox-fg1);
|
|
}
|
|
|
|
.login-container {
|
|
background: var(--gruvbox-bg1);
|
|
padding: 2rem;
|
|
border-radius: 15px;
|
|
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
|
|
width: 100%;
|
|
max-width: 400px;
|
|
border: 1px solid var(--gruvbox-bg3);
|
|
backdrop-filter: blur(10px);
|
|
}
|
|
|
|
.login-header {
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.login-header h1 {
|
|
color: var(--gruvbox-orange);
|
|
margin-bottom: 0.5rem;
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.login-header p {
|
|
color: var(--gruvbox-fg2);
|
|
font-size: 0.9rem;
|
|
font-weight: 400;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
color: var(--gruvbox-fg1);
|
|
font-weight: 600;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 0.875rem;
|
|
border: 2px solid var(--gruvbox-bg3);
|
|
border-radius: 8px;
|
|
font-size: 1rem;
|
|
background: var(--gruvbox-bg2);
|
|
color: var(--gruvbox-fg1);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: var(--gruvbox-blue);
|
|
box-shadow: 0 0 0 3px rgba(131, 165, 152, 0.1);
|
|
background: var(--gruvbox-bg0);
|
|
}
|
|
|
|
.form-group input::placeholder {
|
|
color: var(--gruvbox-fg2);
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.login-btn {
|
|
width: 100%;
|
|
padding: 0.875rem;
|
|
background: linear-gradient(135deg, var(--gruvbox-orange) 0%, var(--gruvbox-red) 100%);
|
|
color: var(--gruvbox-bg0);
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 1rem;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.login-btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 8px 25px rgba(254, 128, 25, 0.3);
|
|
}
|
|
|
|
.login-btn:active {
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.login-btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
box-shadow: none;
|
|
}
|
|
|
|
.error-message {
|
|
background: rgba(251, 73, 52, 0.1);
|
|
color: var(--gruvbox-red);
|
|
padding: 0.875rem;
|
|
border-radius: 8px;
|
|
margin-bottom: 1rem;
|
|
border: 1px solid rgba(251, 73, 52, 0.3);
|
|
display: none;
|
|
backdrop-filter: blur(5px);
|
|
}
|
|
|
|
.success-message {
|
|
background: rgba(184, 187, 38, 0.1);
|
|
color: var(--gruvbox-green);
|
|
padding: 0.875rem;
|
|
border-radius: 8px;
|
|
margin-bottom: 1rem;
|
|
border: 1px solid rgba(184, 187, 38, 0.3);
|
|
display: none;
|
|
backdrop-filter: blur(5px);
|
|
}
|
|
|
|
.loading {
|
|
display: inline-block;
|
|
width: 20px;
|
|
height: 20px;
|
|
border: 3px solid #ffffff;
|
|
border-radius: 50%;
|
|
border-top-color: transparent;
|
|
animation: spin 1s ease-in-out infinite;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
.user-info {
|
|
background: var(--gruvbox-bg2);
|
|
padding: 1.25rem;
|
|
border-radius: 8px;
|
|
margin-top: 1rem;
|
|
display: none;
|
|
border: 1px solid var(--gruvbox-bg3);
|
|
}
|
|
|
|
.user-info h3 {
|
|
margin-bottom: 0.5rem;
|
|
color: var(--gruvbox-green);
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.user-info p {
|
|
margin-bottom: 0.25rem;
|
|
color: var(--gruvbox-fg2);
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.logout-btn {
|
|
background: var(--gruvbox-red);
|
|
color: var(--gruvbox-fg0);
|
|
border: none;
|
|
padding: 0.625rem 1.25rem;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
margin-top: 1rem;
|
|
font-size: 0.9rem;
|
|
font-weight: 600;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.logout-btn:hover {
|
|
background: var(--gruvbox-orange);
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 4px 12px rgba(251, 73, 52, 0.3);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="login-header">
|
|
<h1>PRISM</h1>
|
|
<p>Construction Job Management System</p>
|
|
</div>
|
|
|
|
<div id="error-message" class="error-message"></div>
|
|
<div id="success-message" class="success-message"></div>
|
|
|
|
<div id="login-form">
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input type="email" id="email" placeholder="Enter your email" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" placeholder="Enter your password" required>
|
|
</div>
|
|
|
|
<button id="login-btn" class="login-btn">
|
|
<span id="login-text">Login</span>
|
|
<span id="loading" class="loading" style="display: none;"></span>
|
|
</button>
|
|
</div>
|
|
|
|
<div id="user-info" class="user-info" style="display: none;">
|
|
<h3>Welcome!</h3>
|
|
<p id="user-details"></p>
|
|
<button class="logout-btn" onclick="logout()">Logout</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="module">
|
|
import PocketBase from '/pocketbase.es.mjs';
|
|
|
|
// Initialize PocketBase
|
|
const pb = new PocketBase('https://pocketbase.ccllc.pro');
|
|
|
|
// Optional: Set API key for admin operations (if needed)
|
|
// pb.authStore.save('itlbbkeok6lxtvxvic8dgpugj2962h', null);
|
|
|
|
// Check if user is already authenticated
|
|
if (pb.authStore.isValid) {
|
|
showUserInfo(pb.authStore.model);
|
|
}
|
|
|
|
// Test connection on page load
|
|
testConnection();
|
|
|
|
async function testConnection() {
|
|
try {
|
|
// Test basic connectivity (silent)
|
|
await pb.health.check();
|
|
} catch (error) {
|
|
// Only show user-facing error for real connection issues
|
|
if (error.message && !error.message.includes('autocancelled') && !error.message.includes('aborted')) {
|
|
showError('Unable to connect to server. Please check your internet connection.');
|
|
}
|
|
}
|
|
}
|
|
|
|
async function login() {
|
|
const email = document.getElementById('email').value;
|
|
const password = document.getElementById('password').value;
|
|
const loginBtn = document.getElementById('login-btn');
|
|
const loginText = document.getElementById('login-text');
|
|
const loading = document.getElementById('loading');
|
|
|
|
if (!email || !password) {
|
|
showError('Please fill in all fields');
|
|
return;
|
|
}
|
|
|
|
// Show loading state
|
|
loginBtn.disabled = true;
|
|
loginText.style.display = 'none';
|
|
loading.style.display = 'inline-block';
|
|
|
|
try {
|
|
const authData = await pb.collection('users').authWithPassword(email, password);
|
|
|
|
showSuccess('Login successful! Redirecting to dashboard...');
|
|
|
|
// Clear form
|
|
document.getElementById('email').value = '';
|
|
document.getElementById('password').value = '';
|
|
|
|
// Redirect to dashboard after a short delay
|
|
setTimeout(() => {
|
|
window.location.href = '/dashboard.html';
|
|
}, 1500);
|
|
|
|
} catch (error) {
|
|
// Log error for debugging (can be removed in production)
|
|
console.error('Login failed:', error.message);
|
|
|
|
// Provide more specific error messages
|
|
let errorMessage = 'Login failed. Please try again.';
|
|
|
|
if (error.response) {
|
|
// Server responded with error
|
|
const status = error.response.status;
|
|
const data = error.response.data;
|
|
|
|
if (status === 400) {
|
|
errorMessage = 'Invalid email or password. Please check your credentials.';
|
|
} else if (status === 401) {
|
|
errorMessage = 'Authentication failed. Please check your email and password.';
|
|
} else if (status === 403) {
|
|
errorMessage = 'Access denied. Your account may be disabled.';
|
|
} else if (status === 404) {
|
|
errorMessage = 'User not found. Please check your email address.';
|
|
} else if (status >= 500) {
|
|
errorMessage = 'Server error. Please try again later.';
|
|
} else if (data && data.message) {
|
|
errorMessage = data.message;
|
|
}
|
|
} else if (error.code === 'NETWORK_ERROR' || error.message?.includes('fetch')) {
|
|
errorMessage = 'Network error. Please check your internet connection.';
|
|
} else if (error.message) {
|
|
errorMessage = error.message;
|
|
}
|
|
|
|
showError(errorMessage);
|
|
} finally {
|
|
// Reset loading state
|
|
loginBtn.disabled = false;
|
|
loginText.style.display = 'inline';
|
|
loading.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
function logout() {
|
|
pb.authStore.clear();
|
|
document.getElementById('user-info').style.display = 'none';
|
|
document.getElementById('login-form').style.display = 'block';
|
|
showSuccess('Logged out successfully');
|
|
}
|
|
|
|
// Make logout function globally available
|
|
window.logout = logout;
|
|
|
|
function showUserInfo(user) {
|
|
document.getElementById('login-form').style.display = 'none';
|
|
document.getElementById('user-info').style.display = 'block';
|
|
|
|
const userDetails = document.getElementById('user-details');
|
|
userDetails.innerHTML = `
|
|
<strong>Name:</strong> ${user.name || 'N/A'}<br>
|
|
<strong>Email:</strong> ${user.email}<br>
|
|
<strong>ID:</strong> ${user.id}<br>
|
|
<strong>Created:</strong> ${new Date(user.created).toLocaleDateString()}
|
|
`;
|
|
}
|
|
|
|
function showError(message) {
|
|
const errorDiv = document.getElementById('error-message');
|
|
errorDiv.textContent = message;
|
|
errorDiv.style.display = 'block';
|
|
document.getElementById('success-message').style.display = 'none';
|
|
}
|
|
|
|
function showSuccess(message) {
|
|
const successDiv = document.getElementById('success-message');
|
|
successDiv.textContent = message;
|
|
successDiv.style.display = 'block';
|
|
document.getElementById('error-message').style.display = 'none';
|
|
}
|
|
|
|
// Allow Enter key to submit form
|
|
document.getElementById('password').addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') {
|
|
login();
|
|
}
|
|
});
|
|
|
|
// Handle login button click
|
|
document.getElementById('login-btn').addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
login();
|
|
});
|
|
|
|
// Initialize on page load
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
testConnection();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|