Files
d1041231004-webgis-povertymap/login.php
T
2026-06-10 20:22:46 +07:00

108 lines
3.7 KiB
PHP

<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pdo = new PDO("mysql:host=localhost;dbname=webgis_spbu;charset=utf8mb4", "root", "");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$s = $pdo->prepare("SELECT * FROM users WHERE username=? AND aktif=1");
$s->execute([$username]);
$user = $s->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['password_hash'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['role'] = $user['role'];
$_SESSION['id_ibadah'] = $user['id_ibadah'];
$_SESSION['nama'] = $user['nama_lengkap'];
header('Location: index.php');
exit;
} else {
$error = 'Username atau password salah';
}
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Login — WebGIS Kemiskinan</title>
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700&display=swap" rel="stylesheet"/>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Plus Jakarta Sans', sans-serif;
background: #0d1117;
color: #e6edf3;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.card {
background: #161b22;
border: 1px solid #30363d;
border-radius: 16px;
padding: 36px 32px;
width: 360px;
box-shadow: 0 8px 32px rgba(0,0,0,.6);
}
.logo {
width: 48px; height: 48px;
background: linear-gradient(135deg,#10b981,#059669);
border-radius: 12px;
display: grid; place-items: center;
font-size: 22px;
margin: 0 auto 16px;
}
h1 { text-align: center; font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.sub { text-align: center; font-size: 12px; color: #8b949e; margin-bottom: 28px; }
label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: #8b949e; margin-bottom: 6px; }
input {
width: 100%; background: #21262d; border: 1px solid #30363d;
border-radius: 8px; padding: 10px 13px; color: #e6edf3;
font-size: 14px; font-family: inherit; outline: none;
transition: border-color .2s; margin-bottom: 16px;
}
input:focus { border-color: #10b981; }
button {
width: 100%; background: #10b981; color: #fff;
border: none; border-radius: 8px; padding: 11px;
font-size: 14px; font-weight: 700; cursor: pointer;
font-family: inherit; transition: background .2s;
}
button:hover { background: #0ea371; }
.error {
background: rgba(239,68,68,.12);
border: 1px solid rgba(239,68,68,.3);
border-radius: 8px; padding: 10px 13px;
color: #ef4444; font-size: 13px;
margin-bottom: 16px;
}
</style>
</head>
<body>
<div class="card">
<div class="logo">🗺</div>
<h1>WebGIS Pemetaan Kemiskinan</h1>
<p class="sub">Berbasis Partisipasi Rumah Ibadah</p>
<?php if (!empty($error)): ?>
<div class="error">⚠ <?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Masukkan username" required autofocus/>
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Masukkan password" required/>
<button type="submit">Masuk</button>
</form>
</div>
</body>
</html>