154 lines
4.3 KiB
PHP
154 lines
4.3 KiB
PHP
<?php
|
|
session_start();
|
|
include 'koneksi.php';
|
|
|
|
// Jika sudah login, redirect ke index.php
|
|
if (isset($_SESSION['role'])) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$error = "";
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$username = mysqli_real_escape_string($conn, $_POST['username']);
|
|
$password = $_POST['password'];
|
|
|
|
$sql = "SELECT * FROM users WHERE username = '$username'";
|
|
$result = mysqli_query($conn, $sql);
|
|
|
|
if ($result && mysqli_num_rows($result) > 0) {
|
|
$user = mysqli_fetch_assoc($result);
|
|
|
|
// Verifikasi password hash
|
|
if (password_verify($password, $user['password'])) {
|
|
// Set session
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
$_SESSION['role'] = $user['role'];
|
|
$_SESSION['ibadah_id'] = $user['ibadah_id']; // Bisa null untuk Admin/Walikota
|
|
|
|
header("Location: index.php");
|
|
exit;
|
|
} else {
|
|
$error = "Password salah!";
|
|
}
|
|
} else {
|
|
$error = "Username tidak ditemukan!";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login WebGIS</title>
|
|
<style>
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
margin: 0;
|
|
color: #333;
|
|
}
|
|
.login-container {
|
|
background-color: #fff;
|
|
padding: 40px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
|
|
width: 100%;
|
|
max-width: 320px;
|
|
}
|
|
.login-container h2 {
|
|
text-align: center;
|
|
margin-bottom: 25px;
|
|
color: #2c3e50;
|
|
font-size: 24px;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
font-size: 14px;
|
|
color: #666;
|
|
font-weight: 500;
|
|
}
|
|
.form-control {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 6px;
|
|
box-sizing: border-box;
|
|
font-size: 14px;
|
|
transition: border-color 0.2s;
|
|
}
|
|
.form-control:focus {
|
|
border-color: #3498db;
|
|
outline: none;
|
|
box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
|
|
}
|
|
.btn-login {
|
|
width: 100%;
|
|
padding: 12px;
|
|
background-color: #3498db;
|
|
color: #fff;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s, transform 0.1s;
|
|
}
|
|
.btn-login:hover {
|
|
background-color: #2980b9;
|
|
}
|
|
.btn-login:active {
|
|
transform: scale(0.98);
|
|
}
|
|
.error-message {
|
|
background-color: #ffebee;
|
|
color: #c62828;
|
|
padding: 10px;
|
|
border-radius: 6px;
|
|
margin-bottom: 20px;
|
|
font-size: 13px;
|
|
text-align: center;
|
|
border: 1px solid #ef9a9a;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="login-container">
|
|
<h2>🔐 WebGIS Login</h2>
|
|
|
|
<?php if(!empty($error)): ?>
|
|
<div class="error-message">
|
|
<?php echo $error; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="">
|
|
<div class="form-group">
|
|
<label for="username">Username</label>
|
|
<input type="text" id="username" name="username" class="form-control" required placeholder="Masukkan username" autocomplete="off">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" name="password" class="form-control" required placeholder="Masukkan password">
|
|
</div>
|
|
|
|
<button type="submit" class="btn-login">Login</button>
|
|
</form>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|