Files
WebGIS/WebGISPovertyMap/login.php
T

80 lines
2.7 KiB
PHP

<?php
session_start();
// Jika sudah login sebagai admin, tendang kembali ke index
if (isset($_SESSION['role']) && $_SESSION['role'] === 'admin') {
header("Location: index.php");
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
include 'koneksi.php';
// Query user from database
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ? LIMIT 1");
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result && $result->num_rows > 0) {
$user = $result->fetch_assoc();
// Check hashed password
if (password_verify($password, $user['password'])) {
$_SESSION['role'] = $user['role'];
$_SESSION['username'] = $user['username'];
$_SESSION['avatar'] = $user['avatar'];
header("Location: index.php");
exit;
}
}
$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 Operator - WebGIS Pontianak</title>
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body class="login-body">
<div class="login-card">
<div class="login-logo">
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-.553-.894L15 4m0 13V4m0 0L9 7" />
</svg>
</div>
<h2>Login Operator</h2>
<p>Masuk untuk mengelola data WebGIS</p>
<?php if (isset($error)): ?>
<div class="error-msg"><?php echo $error; ?></div>
<?php endif; ?>
<form method="POST" class="login-form">
<div class="sfield">
<label class="sfield-label">Username</label>
<input type="text" name="username" class="sinput" placeholder="Masukkan username..." required autofocus>
</div>
<div class="sfield">
<label class="sfield-label">Password</label>
<input type="password" name="password" class="sinput" placeholder="Masukkan password..." required>
</div>
<button type="submit" class="btn btn-save" style="width: 100%; margin-top: 8px;">Login ke Sistem</button>
</form>
<a href="index.php" class="back-link">← Kembali ke Peta</a>
</div>
</body>
</html>