209 lines
5.6 KiB
PHP
209 lines
5.6 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Kalau sudah login, langsung redirect ke peta
|
|
if (isset($_SESSION['user'])) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$conn = new mysqli("localhost", "root", "", "webgis");
|
|
|
|
$username = trim($_POST['username']);
|
|
$password = trim($_POST['password']);
|
|
|
|
if ($username && $password) {
|
|
$stmt = $conn->prepare("SELECT id, nama, username, password, role FROM users WHERE username = ?");
|
|
$stmt->bind_param("s", $username);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$user = $result->fetch_assoc();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
// Login berhasil
|
|
$_SESSION['user'] = $user['id'];
|
|
$_SESSION['nama'] = $user['nama'];
|
|
$_SESSION['role'] = $user['role'];
|
|
header("Location: index.php");
|
|
exit;
|
|
} else {
|
|
$error = "Username atau password salah.";
|
|
}
|
|
|
|
$stmt->close();
|
|
} else {
|
|
$error = "Username dan password wajib diisi.";
|
|
}
|
|
|
|
$conn->close();
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Login - Sistem Pemetaan</title>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
body {
|
|
font-family: 'Segoe UI', sans-serif;
|
|
background: #f0f4f8;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.login-card {
|
|
background: white;
|
|
padding: 40px;
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
|
|
width: 100%;
|
|
max-width: 380px;
|
|
}
|
|
|
|
.login-card h2 {
|
|
text-align: center;
|
|
margin-bottom: 8px;
|
|
color: #1B2A4A;
|
|
font-size: 22px;
|
|
}
|
|
|
|
.login-card .subtitle {
|
|
text-align: center;
|
|
color: #888;
|
|
font-size: 13px;
|
|
margin-bottom: 28px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
color: #444;
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
.input-wrapper {
|
|
position: relative;
|
|
}
|
|
|
|
.input-wrapper i {
|
|
position: absolute;
|
|
left: 12px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
color: #aaa;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.input-wrapper input {
|
|
width: 100%;
|
|
padding: 10px 12px 10px 36px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 8px;
|
|
font-size: 14px;
|
|
transition: border-color 0.2s;
|
|
outline: none;
|
|
}
|
|
|
|
.input-wrapper input:focus {
|
|
border-color: #1B2A4A;
|
|
}
|
|
|
|
.error-msg {
|
|
background: #fdecea;
|
|
color: #c0392b;
|
|
padding: 10px 14px;
|
|
border-radius: 8px;
|
|
font-size: 13px;
|
|
margin-bottom: 16px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.btn-submit {
|
|
width: 100%;
|
|
padding: 12px;
|
|
background: #1B2A4A;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: background 0.2s;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
.btn-submit:hover {
|
|
background: #253d6e;
|
|
}
|
|
|
|
.back-link {
|
|
display: block;
|
|
text-align: center;
|
|
margin-top: 16px;
|
|
font-size: 13px;
|
|
color: #888;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.back-link:hover {
|
|
color: #1B2A4A;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-card">
|
|
<h2><i class="fa-solid fa-map-location-dot" style="color:#1B2A4A;"></i> Sistem Pemetaan Kemiskinan</h2>
|
|
<p class="subtitle">Masuk untuk mengelola data peta</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="error-msg">
|
|
<i class="fa-solid fa-circle-exclamation"></i>
|
|
<?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST">
|
|
<div class="form-group">
|
|
<label>Username</label>
|
|
<div class="input-wrapper">
|
|
<i class="fa-solid fa-user"></i>
|
|
<input type="text" name="username" placeholder="Masukkan username"
|
|
value="<?= htmlspecialchars($_POST['username'] ?? '') ?>" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>Password</label>
|
|
<div class="input-wrapper">
|
|
<i class="fa-solid fa-lock"></i>
|
|
<input type="password" name="password" placeholder="Masukkan password" required>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn-submit">
|
|
<i class="fa-solid fa-right-to-bracket"></i> Login
|
|
</button>
|
|
</form>
|
|
|
|
<a href="index.php" class="back-link">
|
|
<i class="fa-solid fa-arrow-left"></i> Kembali ke Peta
|
|
</a>
|
|
</div>
|
|
</body>
|
|
</html>
|