Files
D1041231077-webgis/03/login.html
T
2026-06-10 22:26:03 +07:00

1008 lines
34 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 — BantSOSial GIS Pontianak</title>
<meta name="description" content="Masuk atau daftar akun untuk mengakses sistem WebGIS Distribusi Bantuan Sosial Pontianak">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=DM+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #f0f4f8;
--text: #1e293b;
--text-muted: #64748b;
--primary: #0f766e;
--primary-light: #ccfbf1;
--primary-hover: #0d6563;
--orange: #ea580c;
--orange-light: #ffedd5;
--orange-hover: #c2410c;
--danger: #dc2626;
--danger-light: #fee2e2;
--success: #16a34a;
--success-light: #dcfce7;
--purple: #7c3aed;
--purple-light: #ede9fe;
--border: #e2e8f0;
--radius-sm: 8px;
--radius-md: 12px;
--shadow: 0 4px 24px rgba(0,0,0,0.08);
--shadow-lg: 0 8px 40px rgba(0,0,0,0.14);
--font: 'DM Sans', sans-serif;
--mono: 'DM Mono', monospace;
}
html, body {
min-height: 100%;
height: 100%;
font-family: var(--font);
color: var(--text);
overflow-x: hidden;
}
/* ============================================
BACKGROUND — animated gradient
============================================ */
.login-bg {
position: fixed;
inset: 0;
background: linear-gradient(135deg, #0f766e 0%, #0d9488 25%, #14b8a6 50%, #0f766e 75%, #064e3b 100%);
background-size: 400% 400%;
animation: gradientShift 12s ease infinite;
}
@keyframes gradientShift {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
/* Decorative floating shapes */
.login-bg::before,
.login-bg::after {
content: '';
position: absolute;
border-radius: 50%;
opacity: 0.08;
background: white;
}
.login-bg::before {
width: 600px; height: 600px;
top: -200px; right: -100px;
animation: floatBubble 8s ease-in-out infinite;
}
.login-bg::after {
width: 400px; height: 400px;
bottom: -150px; left: -50px;
animation: floatBubble 10s ease-in-out infinite reverse;
}
@keyframes floatBubble {
0%, 100% { transform: translate(0, 0) scale(1); }
50% { transform: translate(30px, -30px) scale(1.05); }
}
/* Small dots pattern overlay */
.login-pattern {
position: fixed;
inset: 0;
background-image: radial-gradient(circle, rgba(255,255,255,0.06) 1px, transparent 1px);
background-size: 30px 30px;
pointer-events: none;
}
/* ============================================
MAIN CONTAINER
============================================ */
.login-container {
position: relative;
z-index: 10;
display: flex;
align-items: flex-start;
justify-content: center;
min-height: 100vh;
padding: 20px;
overflow-y: auto;
}
.login-card {
background: rgba(255,255,255,0.95);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.3);
border-radius: 20px;
width: 100%;
max-width: 460px;
box-shadow: 0 24px 80px rgba(0,0,0,0.25), 0 0 0 1px rgba(255,255,255,0.1);
animation: cardSlideUp 0.5s ease;
overflow: hidden;
margin: auto;
}
@keyframes cardSlideUp {
from { opacity: 0; transform: translateY(30px) scale(0.97); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
/* ============================================
CARD HEADER — Brand
============================================ */
.login-header {
background: linear-gradient(135deg, #0f766e, #0d9488);
padding: 28px 32px 24px;
text-align: center;
position: relative;
overflow: hidden;
}
.login-header::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 4px;
background: linear-gradient(90deg, var(--orange), #f59e0b, var(--orange));
}
.login-brand-icon {
font-size: 36px;
margin-bottom: 8px;
display: block;
filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}
.login-brand-title {
font-size: 20px;
font-weight: 700;
color: white;
letter-spacing: -0.5px;
margin-bottom: 2px;
}
.login-brand-sub {
font-size: 11px;
color: rgba(255,255,255,0.7);
font-family: var(--mono);
}
/* ============================================
TAB SWITCHER
============================================ */
.auth-tabs {
display: flex;
border-bottom: 1px solid var(--border);
background: #fafafa;
}
.auth-tab {
flex: 1;
padding: 13px 16px;
text-align: center;
font-size: 13px;
font-weight: 700;
font-family: var(--font);
color: var(--text-muted);
background: none;
border: none;
cursor: pointer;
transition: all 0.25s;
position: relative;
}
.auth-tab::after {
content: '';
position: absolute;
bottom: 0;
left: 16px;
right: 16px;
height: 3px;
background: var(--primary);
border-radius: 3px 3px 0 0;
transform: scaleX(0);
transition: transform 0.25s;
}
.auth-tab:hover { color: var(--text); background: rgba(0,0,0,0.02); }
.auth-tab.active {
color: var(--primary);
}
.auth-tab.active::after {
transform: scaleX(1);
}
/* ============================================
FORMS
============================================ */
.auth-form-wrapper {
padding: 24px 28px 28px;
display: none;
animation: formFadeIn 0.3s ease;
}
.auth-form-wrapper.active {
display: block;
}
@keyframes formFadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.form-group {
margin-bottom: 16px;
}
.form-label {
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.6px;
color: var(--text-muted);
margin-bottom: 6px;
display: block;
}
.form-input {
width: 100%;
padding: 11px 14px;
border: 1.5px solid var(--border);
border-radius: var(--radius-sm);
font-family: var(--font);
font-size: 13px;
color: var(--text);
outline: none;
transition: all 0.2s;
background: white;
}
.form-input:focus {
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(15,118,110,0.1);
}
.form-input.error {
border-color: var(--danger);
box-shadow: 0 0 0 3px rgba(220,38,38,0.1);
}
.form-input-icon-wrap {
position: relative;
}
.form-input-icon-wrap .form-input {
padding-left: 40px;
}
.form-input-icon {
position: absolute;
left: 13px;
top: 50%;
transform: translateY(-50%);
font-size: 15px;
pointer-events: none;
}
.password-toggle {
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
font-size: 16px;
cursor: pointer;
padding: 4px;
opacity: 0.5;
transition: opacity 0.2s;
}
.password-toggle:hover { opacity: 1; }
/* Role selector cards */
.role-selector {
display: flex;
flex-direction: column;
gap: 8px;
}
.role-option {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 14px;
border: 2px solid var(--border);
border-radius: var(--radius-sm);
cursor: pointer;
transition: all 0.2s;
background: var(--bg);
}
.role-option:hover {
border-color: var(--primary);
background: var(--primary-light);
transform: translateX(3px);
}
.role-option.selected {
border-color: var(--primary);
background: var(--primary-light);
}
.role-option.selected[data-role="surveyer"] {
border-color: var(--orange);
background: var(--orange-light);
}
.role-option.selected[data-role="viewer"] {
border-color: var(--purple);
background: var(--purple-light);
}
.role-option-icon {
font-size: 22px;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
background: white;
border-radius: 8px;
flex-shrink: 0;
}
.role-option-info {
flex: 1;
}
.role-option-name {
font-size: 13px;
font-weight: 700;
}
.role-option-desc {
font-size: 10px;
color: var(--text-muted);
line-height: 1.3;
margin-top: 1px;
}
.role-option-check {
width: 20px;
height: 20px;
border: 2px solid var(--border);
border-radius: 50%;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
font-size: 11px;
color: white;
}
.role-option.selected .role-option-check {
background: var(--primary);
border-color: var(--primary);
}
.role-option.selected[data-role="surveyer"] .role-option-check {
background: var(--orange);
border-color: var(--orange);
}
.role-option.selected[data-role="viewer"] .role-option-check {
background: var(--purple);
border-color: var(--purple);
}
/* Lupa Password */
.forgot-link {
margin-top: 10px;
}
.forgot-link button {
width: 100%;
padding: 10px;
background: white;
border: 1.5px dashed #cbd5e1;
border-radius: var(--radius-sm);
color: var(--text-muted);
font-size: 12px;
font-weight: 600;
cursor: pointer;
font-family: var(--font);
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
.forgot-link button:hover {
background: #f0fdf4;
border-color: var(--primary);
color: var(--primary);
}
.forgot-panel {
display: none;
background: #f0fdf4;
border: 1px solid #bbf7d0;
border-radius: var(--radius-sm);
padding: 16px;
margin-bottom: 14px;
animation: formFadeIn 0.3s ease;
}
.forgot-panel.show { display: block; }
.forgot-panel-title {
font-size: 12px;
font-weight: 700;
color: var(--primary);
margin-bottom: 8px;
}
.forgot-panel-sub {
font-size: 11px;
color: var(--text-muted);
margin-bottom: 10px;
line-height: 1.4;
}
.forgot-panel .form-input {
margin-bottom: 8px;
}
.forgot-submit {
width: 100%;
padding: 9px;
background: var(--primary);
color: white;
border: none;
border-radius: var(--radius-sm);
font-family: var(--font);
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: all 0.2s;
}
.forgot-submit:hover { background: var(--primary-hover); }
.forgot-submit:disabled { opacity: 0.6; cursor: not-allowed; }
/* Submit button */
.auth-submit {
width: 100%;
padding: 13px;
background: linear-gradient(135deg, var(--primary), #0d9488);
color: white;
border: none;
border-radius: var(--radius-md);
font-family: var(--font);
font-size: 14px;
font-weight: 700;
cursor: pointer;
transition: all 0.25s;
box-shadow: 0 4px 16px rgba(15,118,110,0.35);
margin-top: 4px;
position: relative;
overflow: hidden;
}
.auth-submit:hover {
transform: translateY(-1px);
box-shadow: 0 6px 24px rgba(15,118,110,0.45);
}
.auth-submit:active {
transform: translateY(0);
}
.auth-submit.register-btn {
background: linear-gradient(135deg, var(--orange), #f97316);
box-shadow: 0 4px 16px rgba(234,88,12,0.35);
}
.auth-submit.register-btn:hover {
box-shadow: 0 6px 24px rgba(234,88,12,0.45);
}
.auth-submit:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
/* Loading spinner inside button */
.auth-submit .spinner {
display: none;
width: 18px;
height: 18px;
border: 2.5px solid rgba(255,255,255,0.3);
border-top-color: white;
border-radius: 50%;
animation: spin 0.6s linear infinite;
margin: 0 auto;
}
.auth-submit.loading .btn-text { display: none; }
.auth-submit.loading .spinner { display: block; }
@keyframes spin {
to { transform: rotate(360deg); }
}
/* Error/Success message */
.auth-message {
padding: 10px 14px;
border-radius: var(--radius-sm);
font-size: 12px;
font-weight: 600;
margin-bottom: 14px;
display: none;
align-items: center;
gap: 8px;
animation: formFadeIn 0.2s ease;
}
.auth-message.show { display: flex; }
.auth-message.error {
background: var(--danger-light);
color: var(--danger);
border: 1px solid #fca5a5;
}
.auth-message.success {
background: var(--success-light);
color: var(--success);
border: 1px solid #86efac;
}
/* Footer */
.login-footer {
text-align: center;
padding: 16px 28px 20px;
border-top: 1px solid var(--border);
font-size: 11px;
color: var(--text-muted);
background: #fafafa;
}
.login-footer a {
color: var(--primary);
text-decoration: none;
font-weight: 600;
}
.login-footer a:hover { text-decoration: underline; }
/* ============================================
RESPONSIVE
============================================ */
@media (max-width: 520px) {
.login-card {
border-radius: 16px;
max-width: 100%;
}
.login-header { padding: 22px 20px 18px; }
.auth-form-wrapper { padding: 20px 20px 24px; }
}
</style>
</head>
<body>
<div class="login-bg"></div>
<div class="login-pattern"></div>
<div class="login-container">
<div class="login-card">
<!-- Header Brand -->
<div class="login-header">
<span class="login-brand-icon">🕌</span>
<div class="login-brand-title">BantSOSial GIS</div>
<div class="login-brand-sub">Pontianak · Kalimantan Barat</div>
</div>
<!-- Tab Switcher -->
<div class="auth-tabs">
<button class="auth-tab active" id="tabLogin" onclick="switchTab('login')">
🔑 Masuk
</button>
<button class="auth-tab" id="tabRegister" onclick="switchTab('register')">
📝 Daftar Akun
</button>
</div>
<!-- ========== LOGIN FORM ========== -->
<div class="auth-form-wrapper active" id="formLogin">
<div class="auth-message" id="loginMessage"></div>
<div class="form-group">
<label class="form-label">Email</label>
<div class="form-input-icon-wrap">
<span class="form-input-icon">📧</span>
<input type="email" id="loginEmail" class="form-input" placeholder="contoh@email.com" autocomplete="email"/>
</div>
</div>
<div class="form-group">
<label class="form-label">Password</label>
<div class="form-input-icon-wrap">
<span class="form-input-icon">🔒</span>
<input type="password" id="loginPassword" class="form-input" placeholder="Masukkan password..." autocomplete="current-password"/>
<button class="password-toggle" type="button" onclick="togglePassword('loginPassword', this)">👁</button>
</div>
</div>
<button class="auth-submit" id="btnLogin" onclick="doLogin()">
<span class="btn-text">🚀 Masuk</span>
<div class="spinner"></div>
</button>
<!-- Lupa Password -->
<div class="forgot-link">
<button type="button" onclick="toggleForgot()">Lupa Password?</button>
</div>
<div class="forgot-panel" id="forgotPanel">
<div class="forgot-panel-title">🔑 Reset Password</div>
<div class="forgot-panel-sub">Masukkan email Anda. Admin akan mereset password dan memberi tahu Anda password baru.</div>
<div class="auth-message" id="forgotMessage"></div>
<input type="email" id="forgotEmail" class="form-input" placeholder="📧 Email terdaftar Anda..."/>
<button class="forgot-submit" id="btnForgot" onclick="doForgotPassword()">Kirim Permintaan ke Admin</button>
</div>
</div>
<!-- ========== REGISTER FORM ========== -->
<div class="auth-form-wrapper" id="formRegister">
<div class="auth-message" id="registerMessage"></div>
<div class="form-group">
<label class="form-label">Nama Lengkap</label>
<div class="form-input-icon-wrap">
<span class="form-input-icon">👤</span>
<input type="text" id="regName" class="form-input" placeholder="Nama Anda..." autocomplete="name"/>
</div>
</div>
<div class="form-group">
<label class="form-label">Email</label>
<div class="form-input-icon-wrap">
<span class="form-input-icon">📧</span>
<input type="email" id="regEmail" class="form-input" placeholder="contoh@email.com" autocomplete="email"/>
</div>
</div>
<div class="form-group">
<label class="form-label">Password (min. 6 karakter)</label>
<div class="form-input-icon-wrap">
<span class="form-input-icon">🔒</span>
<input type="password" id="regPassword" class="form-input" placeholder="Buat password..." autocomplete="new-password"/>
<button class="password-toggle" type="button" onclick="togglePassword('regPassword', this)">👁</button>
</div>
</div>
<div class="form-group">
<label class="form-label">Konfirmasi Password</label>
<div class="form-input-icon-wrap">
<span class="form-input-icon">🔒</span>
<input type="password" id="regPasswordConfirm" class="form-input" placeholder="Ulangi password..." autocomplete="new-password"/>
</div>
</div>
<div class="form-group">
<label class="form-label">Pilih Role</label>
<div class="role-selector">
<div class="role-option" data-role="viewer" onclick="selectRole('viewer')">
<div class="role-option-icon">👁</div>
<div class="role-option-info">
<div class="role-option-name">Masyarakat / Viewer</div>
<div class="role-option-desc">Lihat peta, kirim laporan, lihat history</div>
</div>
<div class="role-option-check"></div>
</div>
<div class="role-option" data-role="surveyer" onclick="selectRole('surveyer')">
<div class="role-option-icon">📋</div>
<div class="role-option-info">
<div class="role-option-name">Surveyer</div>
<div class="role-option-desc">Input data, kelola & lihat laporan</div>
</div>
<div class="role-option-check"></div>
</div>
</div>
<input type="hidden" id="regRole" value="viewer"/>
</div>
<button class="auth-submit register-btn" id="btnRegister" onclick="doRegister()">
<span class="btn-text">📝 Daftar Akun</span>
<div class="spinner"></div>
</button>
</div>
<!-- Footer -->
<div class="login-footer">
WebGIS Distribusi Bantuan Sosial · Pontianak 2025
</div>
</div>
</div>
<script>
// ============================================================
// TAB SWITCHING
// ============================================================
function switchTab(tab) {
const tabLogin = document.getElementById('tabLogin');
const tabRegister = document.getElementById('tabRegister');
const formLogin = document.getElementById('formLogin');
const formRegister = document.getElementById('formRegister');
if (tab === 'login') {
tabLogin.classList.add('active');
tabRegister.classList.remove('active');
formLogin.classList.add('active');
formRegister.classList.remove('active');
} else {
tabLogin.classList.remove('active');
tabRegister.classList.add('active');
formLogin.classList.remove('active');
formRegister.classList.add('active');
}
// Clear messages
hideMessage('loginMessage');
hideMessage('registerMessage');
}
// ============================================================
// ROLE SELECTION
// ============================================================
let selectedRole = 'viewer';
function selectRole(role) {
selectedRole = role;
document.getElementById('regRole').value = role;
document.querySelectorAll('.role-option').forEach(el => {
el.classList.remove('selected');
});
const selected = document.querySelector(`.role-option[data-role="${role}"]`);
if (selected) selected.classList.add('selected');
}
// Default select viewer
selectRole('viewer');
// ============================================================
// PASSWORD TOGGLE
// ============================================================
function togglePassword(inputId, btn) {
const input = document.getElementById(inputId);
if (input.type === 'password') {
input.type = 'text';
btn.textContent = '🙈';
} else {
input.type = 'password';
btn.textContent = '👁';
}
}
// ============================================================
// MESSAGES
// ============================================================
function showMessage(elId, type, text) {
const el = document.getElementById(elId);
el.className = `auth-message show ${type}`;
el.innerHTML = (type === 'error' ? '⚠️ ' : '✅ ') + text;
}
function hideMessage(elId) {
const el = document.getElementById(elId);
if (el) { el.className = 'auth-message'; el.innerHTML = ''; }
}
// ============================================================
// LOGIN
// ============================================================
async function doLogin() {
const email = document.getElementById('loginEmail').value.trim();
const password = document.getElementById('loginPassword').value;
const btn = document.getElementById('btnLogin');
hideMessage('loginMessage');
// Validate
if (!email) {
showMessage('loginMessage', 'error', 'Email wajib diisi');
document.getElementById('loginEmail').classList.add('error');
document.getElementById('loginEmail').focus();
return;
}
if (!password) {
showMessage('loginMessage', 'error', 'Password wajib diisi');
document.getElementById('loginPassword').classList.add('error');
document.getElementById('loginPassword').focus();
return;
}
// Clear error styles
document.querySelectorAll('.form-input').forEach(el => el.classList.remove('error'));
btn.classList.add('loading');
btn.disabled = true;
try {
const res = await fetch('auth_login.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `email=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`
});
const data = await res.json();
if (data.success) {
showMessage('loginMessage', 'success', 'Login berhasil! Mengalihkan...');
setTimeout(() => {
window.location.href = 'index.php';
}, 800);
} else {
showMessage('loginMessage', 'error', data.message || 'Login gagal');
}
} catch (err) {
showMessage('loginMessage', 'error', 'Gagal menghubungi server');
}
btn.classList.remove('loading');
btn.disabled = false;
}
// ============================================================
// REGISTER
// ============================================================
async function doRegister() {
const nama = document.getElementById('regName').value.trim();
const email = document.getElementById('regEmail').value.trim();
const password = document.getElementById('regPassword').value;
const confirm = document.getElementById('regPasswordConfirm').value;
const role = document.getElementById('regRole').value;
const btn = document.getElementById('btnRegister');
hideMessage('registerMessage');
document.querySelectorAll('.form-input').forEach(el => el.classList.remove('error'));
// Validate
if (!nama) {
showMessage('registerMessage', 'error', 'Nama wajib diisi');
document.getElementById('regName').classList.add('error');
document.getElementById('regName').focus();
return;
}
if (!email) {
showMessage('registerMessage', 'error', 'Email wajib diisi');
document.getElementById('regEmail').classList.add('error');
document.getElementById('regEmail').focus();
return;
}
if (password.length < 6) {
showMessage('registerMessage', 'error', 'Password minimal 6 karakter');
document.getElementById('regPassword').classList.add('error');
document.getElementById('regPassword').focus();
return;
}
if (password !== confirm) {
showMessage('registerMessage', 'error', 'Konfirmasi password tidak cocok');
document.getElementById('regPasswordConfirm').classList.add('error');
document.getElementById('regPasswordConfirm').focus();
return;
}
btn.classList.add('loading');
btn.disabled = true;
try {
const res = await fetch('auth_register.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `nama=${encodeURIComponent(nama)}&email=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}&role=${encodeURIComponent(role)}`
});
const data = await res.json();
if (data.success) {
showMessage('registerMessage', 'success', data.message);
setTimeout(() => {
// Pindah ke tab login
switchTab('login');
// Isi form email login dari pendaftaran
document.getElementById('loginEmail').value = email;
document.getElementById('loginPassword').focus();
}, 3000);
} else {
showMessage('registerMessage', 'error', data.message || 'Registrasi gagal');
}
} catch (err) {
showMessage('registerMessage', 'error', 'Gagal menghubungi server');
}
btn.classList.remove('loading');
btn.disabled = false;
}
// ============================================================
// KEYBOARD SUPPORT
// ============================================================
document.getElementById('loginPassword').addEventListener('keydown', e => {
if (e.key === 'Enter') doLogin();
});
document.getElementById('loginEmail').addEventListener('keydown', e => {
if (e.key === 'Enter') doLogin();
});
document.getElementById('regPasswordConfirm').addEventListener('keydown', e => {
if (e.key === 'Enter') doRegister();
});
// ============================================================
// LUPA PASSWORD
// ============================================================
function toggleForgot() {
const panel = document.getElementById('forgotPanel');
const isShown = panel.classList.contains('show');
panel.classList.toggle('show');
if (!isShown) {
// Auto-fill email dari field login jika sudah diisi
const loginEmail = document.getElementById('loginEmail').value;
if (loginEmail) document.getElementById('forgotEmail').value = loginEmail;
document.getElementById('forgotEmail').focus();
}
hideMessage('forgotMessage');
}
async function doForgotPassword() {
const email = document.getElementById('forgotEmail').value.trim();
const btn = document.getElementById('btnForgot');
hideMessage('forgotMessage');
if (!email || !email.includes('@')) {
showMessage('forgotMessage', 'error', 'Masukkan email yang valid');
document.getElementById('forgotEmail').focus();
return;
}
btn.disabled = true;
btn.textContent = 'Mengirim...';
try {
const res = await fetch('request_reset.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `email=${encodeURIComponent(email)}`
});
const data = await res.json();
if (data.success) {
showMessage('forgotMessage', 'success', data.message);
btn.textContent = '✅ Terkirim';
} else {
showMessage('forgotMessage', 'error', data.message || 'Gagal mengirim permintaan');
btn.disabled = false;
btn.textContent = 'Kirim Permintaan ke Admin';
}
} catch (err) {
showMessage('forgotMessage', 'error', 'Gagal menghubungi server');
btn.disabled = false;
btn.textContent = 'Kirim Permintaan ke Admin';
}
}
// Clear error on input
document.querySelectorAll('.form-input').forEach(el => {
el.addEventListener('input', () => el.classList.remove('error'));
});
// ============================================================
// CHECK IF ALREADY LOGGED IN
// ============================================================
(async function checkSession() {
try {
const res = await fetch('auth_check.php');
const data = await res.json();
if (data.logged_in) {
window.location.href = 'index.php';
}
} catch (e) { /* server not available, stay on login */ }
})();
</script>
</body>
</html>