Spaces:
Running
Running
File size: 4,307 Bytes
6b3c4b4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WASTE-LESS - Admin Login</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<!-- Header with back button -->
<header class="bg-blue-600 text-white rounded-lg shadow-lg p-6 mb-8">
<div class="flex items-center">
<a href="index.html" class="text-blue-100 hover:text-white mr-4 text-xl"><i class="fas fa-home"></i></a>
<div>
<h1 class="text-3xl font-bold">Admin Login</h1>
<p class="text-blue-100">Access the admin dashboard</p>
</div>
</div>
</header>
<!-- Login Form -->
<div class="bg-white rounded-lg shadow-md p-8 max-w-md mx-auto">
<form id="login-form">
<div class="mb-6">
<label for="username" class="block text-gray-700 font-medium mb-2">Username</label>
<input type="text" id="username" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div>
<div class="mb-6">
<label for="password" class="block text-gray-700 font-medium mb-2">Password</label>
<input type="password" id="password" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div>
<button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded-lg transition duration-200">
<i class="fas fa-sign-in-alt mr-2"></i> Login
</button>
</form>
</div>
</div>
<script>
document.getElementById('login-form').addEventListener('submit', function(e) {
e.preventDefault();
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value;
const submitBtn = document.querySelector('#login-form button');
const originalBtnText = submitBtn.innerHTML;
// Add loading state
submitBtn.disabled = true;
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Authenticating...';
try {
// Verify credentials (hardcoded)
if (username === 'Oppanigas' && password === 'barberkesayangan') {
// Store login state in localStorage
localStorage.setItem('isAdminLoggedIn', 'true');
localStorage.setItem('lastLogin', new Date().toISOString());
// Redirect to admin dashboard
window.location.href = 'admin-dashboard.html';
} else {
throw new Error('Invalid username or password');
}
} catch (error) {
console.error('Login error:', error);
alert(error.message || 'Login failed. Please try again.');
} finally {
submitBtn.disabled = false;
submitBtn.innerHTML = originalBtnText;
}
});
// Check if already logged in and session is still valid
if (localStorage.getItem('isAdminLoggedIn') === 'true') {
const lastLogin = localStorage.getItem('lastLogin');
const sessionTimeout = 4 * 60 * 60 * 1000; // 4 hours
if (lastLogin && (Date.now() - new Date(lastLogin).getTime()) < sessionTimeout) {
localStorage.setItem('fromLoginPage', 'true');
window.location.href = 'admin-dashboard.html';
} else {
// Session expired
localStorage.removeItem('isAdminLoggedIn');
localStorage.removeItem('lastLogin');
}
}
</script>
</body>
</html> |