123 lines
3.7 KiB
PHP
123 lines
3.7 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Jika sudah login, redirect ke dashboard
|
|
if (isset($_SESSION['user_id'])) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = $_POST['username'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (!empty($username) && !empty($password)) {
|
|
try {
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
$_SESSION['nama_lengkap'] = $user['nama_lengkap'];
|
|
$_SESSION['role'] = $user['role'];
|
|
|
|
header('Location: index.php');
|
|
exit;
|
|
} else {
|
|
$error = 'Username atau password salah.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error = 'Terjadi kesalahan sistem.';
|
|
}
|
|
} else {
|
|
$error = 'Silakan isi username dan password.';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login SiWarga - Aplikasi Administrasi RT/RW</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
font-family: 'Inter', sans-serif;
|
|
background-color: #f8fafc;
|
|
height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.login-card {
|
|
width: 100%;
|
|
max-width: 400px;
|
|
padding: 2rem;
|
|
border-radius: 1rem;
|
|
background: white;
|
|
box-shadow: 0 10px 25px rgba(0,0,0,0.05);
|
|
}
|
|
.btn-primary {
|
|
background-color: #0f172a;
|
|
border: none;
|
|
padding: 0.75rem;
|
|
font-weight: 600;
|
|
}
|
|
.btn-primary:hover {
|
|
background-color: #1e293b;
|
|
}
|
|
.logo {
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
}
|
|
.logo h2 {
|
|
font-weight: 700;
|
|
color: #0f172a;
|
|
margin-bottom: 0;
|
|
}
|
|
.logo p {
|
|
color: #64748b;
|
|
font-size: 0.875rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-card">
|
|
<div class="logo">
|
|
<h2>SiWarga</h2>
|
|
<p>Sistem Administrasi RT/RW Digital</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger" role="alert">
|
|
<?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST">
|
|
<div class="mb-3">
|
|
<label for="username" class="form-label">Username</label>
|
|
<input type="text" class="form-control" id="username" name="username" required autofocus>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label">Password</label>
|
|
<input type="password" class="form-control" id="password" name="password" required>
|
|
</div>
|
|
<div class="mb-4">
|
|
<div class="form-text">
|
|
Gunakan <b>admin</b> / <b>password123</b> untuk demo.
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary w-100">Login ke Sistem</button>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|