117 lines
5.3 KiB
HTML
117 lines
5.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login - WebGIS SPBU & Kemiskinan</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
|
<style>
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
body { font-family: 'Inter', sans-serif; background: #0f172a; color: #f1f5f9; display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
|
|
.login-container { background: #1e293b; padding: 40px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); width: 100%; max-width: 400px; position: relative; }
|
|
.login-container h2 { margin-bottom: 24px; text-align: center; color: #3b82f6; }
|
|
.form-group { margin-bottom: 20px; }
|
|
.form-group label { display: block; margin-bottom: 8px; font-size: 14px; color: #cbd5e1; }
|
|
.form-group input { width: 100%; padding: 12px; border: 1px solid #334155; border-radius: 8px; background: #0f172a; color: #f1f5f9; font-size: 14px; outline: none; }
|
|
.form-group input:focus { border-color: #3b82f6; }
|
|
.btn { width: 100%; padding: 12px; background: #3b82f6; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: 0.2s; }
|
|
.btn:hover { background: #2563eb; }
|
|
.btn-success { background: #22c55e; }
|
|
.btn-success:hover { background: #16a34a; }
|
|
.error-message, .success-message { font-size: 14px; margin-bottom: 16px; text-align: center; display: none; padding: 10px; border-radius: 6px; }
|
|
.error-message { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); }
|
|
.success-message { background: rgba(34, 197, 94, 0.1); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.2); }
|
|
.back-link { display: block; text-align: center; margin-top: 20px; color: #94a3b8; text-decoration: none; font-size: 14px; }
|
|
.back-link:hover { color: #f1f5f9; }
|
|
|
|
.form-section { display: none; }
|
|
.form-section.active { display: block; }
|
|
|
|
@media (max-width: 480px) {
|
|
body { align-items: flex-start; padding: 18px 14px; }
|
|
.login-container { padding: 28px 20px; border-radius: 10px; }
|
|
.login-container h2 { font-size: 22px; margin-bottom: 20px; }
|
|
.form-group { margin-bottom: 16px; }
|
|
.form-group input, .btn { min-height: 44px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="login-container">
|
|
<div id="error-message" class="error-message"></div>
|
|
<div id="success-message" class="success-message"></div>
|
|
|
|
<!-- Login Form -->
|
|
<div id="login-section" class="form-section active">
|
|
<h2>Login Sistem</h2>
|
|
<form id="login-form">
|
|
<div class="form-group">
|
|
<label for="username">Username</label>
|
|
<input type="text" id="username" required placeholder="Masukkan username">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" required placeholder="Masukkan password">
|
|
</div>
|
|
<button type="submit" class="btn">Login</button>
|
|
</form>
|
|
</div>
|
|
<a href="index.php" class="back-link">← Kembali ke Beranda</a>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
function showMessage(type, msg) {
|
|
const errDiv = document.getElementById('error-message');
|
|
const succDiv = document.getElementById('success-message');
|
|
errDiv.style.display = 'none';
|
|
succDiv.style.display = 'none';
|
|
|
|
if (type === 'error') {
|
|
errDiv.textContent = msg;
|
|
errDiv.style.display = 'block';
|
|
} else {
|
|
succDiv.textContent = msg;
|
|
succDiv.style.display = 'block';
|
|
}
|
|
}
|
|
|
|
// Login Handler
|
|
document.getElementById('login-form').addEventListener('submit', async function(e) {
|
|
e.preventDefault();
|
|
const username = document.getElementById('username').value;
|
|
const password = document.getElementById('password').value;
|
|
|
|
try {
|
|
const response = await fetch('backend/login.php', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ username, password })
|
|
});
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success') {
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const redirect = urlParams.get('redirect') || 'admin.html';
|
|
|
|
if (redirect.includes('admin.html') && username !== 'admin') {
|
|
showMessage('error', 'Akses Ditolak: Akun Anda bukan Administrator.');
|
|
// Optionally log them out since they logged into the wrong place
|
|
fetch('backend/logout.php');
|
|
return;
|
|
}
|
|
|
|
window.location.href = redirect;
|
|
} else {
|
|
showMessage('error', data.message);
|
|
}
|
|
} catch (err) {
|
|
showMessage('error', 'Terjadi kesalahan server saat login');
|
|
}
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|