2nd commit: Pemisahan halaman autentifikasi dengan halaman utama, modifikasi ikon, dan pemisahakan fitur berdasarkan role
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
session_start();
|
||||
if(isset($_SESSION['user_id'])) {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - WebGIS Pontianak V2</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<style>
|
||||
body { margin: 0; background: #cbd5e0; display: flex; align-items: center; justify-content: center; height: 100vh; }
|
||||
.auth-overlay { position: static; background: transparent; display: flex !important; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="auth-screen" class="auth-overlay">
|
||||
<div class="auth-box">
|
||||
<h2 style="color: var(--navy); margin-top: 0; text-align: center; border-bottom: 2px solid var(--border); padding-bottom: 10px;">WebGIS Pontianak</h2>
|
||||
|
||||
<!-- Toggle Tabs Form -->
|
||||
<div style="display:flex; margin-bottom: 20px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border);">
|
||||
<button id="tab-login" class="auth-tab active" onclick="switchAuthTab('login')">Masuk</button>
|
||||
<button id="tab-register" class="auth-tab" onclick="switchAuthTab('register')">Daftar</button>
|
||||
</div>
|
||||
|
||||
<!-- Form Autentikasi -->
|
||||
<div class="form-group">
|
||||
<label>Username</label>
|
||||
<input type="text" id="auth-username" placeholder="Masukkan username">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<input type="password" id="auth-password" placeholder="Masukkan password">
|
||||
</div>
|
||||
|
||||
<button id="btn-submit-auth" class="btn btn-save" style="width: 100%; padding: 12px; margin-top: 15px; font-size: 1rem;" onclick="eksekusiAuth()">Login Sistem</button>
|
||||
|
||||
<p id="auth-error-msg" style="color: var(--red-danger); font-size: 0.8rem; text-align: center; margin-top: 10px; font-weight: bold; min-height: 15px;"></p>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
let authMode = 'login';
|
||||
|
||||
function switchAuthTab(mode) {
|
||||
authMode = mode;
|
||||
document.getElementById('tab-login').classList.toggle('active', mode === 'login');
|
||||
document.getElementById('tab-register').classList.toggle('active', mode === 'register');
|
||||
document.getElementById('btn-submit-auth').innerText = mode === 'login' ? 'Login Sistem' : 'Daftar Akun Baru';
|
||||
document.getElementById('auth-error-msg').innerText = '';
|
||||
}
|
||||
|
||||
function eksekusiAuth() {
|
||||
const user = document.getElementById('auth-username').value;
|
||||
const pass = document.getElementById('auth-password').value;
|
||||
const errMsg = document.getElementById('auth-error-msg');
|
||||
|
||||
if(!user || !pass) { errMsg.innerText = "Username dan Password wajib diisi!"; return; }
|
||||
if(authMode === 'register' && pass.length < 8) {
|
||||
errMsg.innerText = "Password minimal harus 8 karakter!";
|
||||
return;
|
||||
}
|
||||
errMsg.innerText = "Memproses...";
|
||||
|
||||
const endpoint = authMode === 'login' ? 'otak_auth/api_login.php' : 'otak_auth/api_register.php';
|
||||
|
||||
fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: user, password: pass })
|
||||
})
|
||||
.then(res => res.json().then(data => ({ok: res.ok, data})))
|
||||
.then(res => {
|
||||
if(!res.ok) throw new Error(res.data.error || "Terjadi kesalahan.");
|
||||
if(authMode === 'register') {
|
||||
alert(res.data.pesan);
|
||||
switchAuthTab('login');
|
||||
} else {
|
||||
sessionStorage.setItem('just_logged_in', 'true');
|
||||
window.location.href = 'index.php'; // Redirect ke utama
|
||||
}
|
||||
})
|
||||
.catch(err => { errMsg.innerText = err.message; });
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user