91 lines
4.8 KiB
PHP
91 lines
4.8 KiB
PHP
<?php
|
|
require_once 'includes/db.php';
|
|
require_once 'includes/auth.php';
|
|
|
|
if (isLoggedIn()) {
|
|
header("Location: dashboard.php");
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if ($username && $password) {
|
|
$stmt = $pdo->prepare("SELECT id, password, full_name as name, role, is_active as status FROM users WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
if ($user['status'] == 1) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['name'] = $user['name'];
|
|
$_SESSION['role'] = $user['role'];
|
|
|
|
$_SESSION['flash'] = [
|
|
'type' => 'success',
|
|
'title' => 'เข้าสู่ระบบสำเร็จ',
|
|
'message' => 'ยินดีต้อนรับเข้าสู่ระบบงานนเรนทรอ่าวไทย'
|
|
];
|
|
header("Location: dashboard.php");
|
|
exit;
|
|
} else {
|
|
$error = 'บัญชีผู้ใช้นี้ถูกระงับการเข้าใช้งานชั่วคราว';
|
|
}
|
|
} else {
|
|
$error = 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง';
|
|
}
|
|
} else {
|
|
$error = 'กรุณากรอกชื่อผู้ใช้และรหัสผ่าน';
|
|
}
|
|
}
|
|
|
|
require_once 'includes/header.php';
|
|
?>
|
|
|
|
<div class="flex-1 flex items-center justify-center p-4 md:p-8 bg-gradient-to-br from-slate-900 via-blue-950 to-slate-950 min-h-screen">
|
|
<div class="w-full max-w-md bg-white rounded-3xl shadow-2xl overflow-hidden border border-slate-100 p-6 md:p-8 space-y-6 animate-fadeIn">
|
|
<div class="text-center space-y-2">
|
|
<div class="mx-auto w-14 h-14 bg-blue-600 rounded-2xl text-white shadow-xl shadow-blue-500/20 flex items-center justify-center">
|
|
<i data-lucide="shield-alert" class="w-8 h-8"></i>
|
|
</div>
|
|
<h2 class="text-xl md:text-2xl font-black text-slate-900 tracking-tight">ระบบบริหารจัดการ นเรนทรอ่าวไทย</h2>
|
|
<p class="text-xs text-slate-400 font-bold">กรุณาเข้าสู่ระบบด้วยรหัสผ่านเพื่อเริ่มต้นปฏิบัติงาน</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="bg-rose-50 border border-rose-200 text-rose-600 px-4 py-3 rounded-xl text-xs font-semibold leading-relaxed text-center">
|
|
<?php echo htmlspecialchars($error); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="index.php" class="space-y-4">
|
|
<div>
|
|
<label for="username" class="block text-xs font-bold text-slate-500 mb-1.5 uppercase tracking-wider">ชื่อบัญชีผู้ใช้งาน</label>
|
|
<input type="text" id="username" name="username" required
|
|
class="w-full py-2.5 px-3.5 border border-slate-200 focus:border-indigo-500 rounded-xl text-center text-lg font-mono tracking-widest text-slate-800 outline-none transition-all"
|
|
placeholder="admin">
|
|
</div>
|
|
|
|
<div>
|
|
<label for="password" class="block text-xs font-bold text-slate-500 mb-1.5 uppercase tracking-wider">รหัสผ่าน</label>
|
|
<input type="password" id="password" name="password" required
|
|
class="w-full py-2.5 px-3.5 border border-slate-200 focus:border-indigo-500 rounded-xl text-center text-lg font-mono tracking-widest text-slate-800 outline-none transition-all"
|
|
placeholder="รหัสผ่าน">
|
|
</div>
|
|
|
|
<button type="submit" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-black py-3 px-4 rounded-xl shadow-md shadow-indigo-200 transition-all active:scale-95 flex items-center justify-center gap-2 cursor-pointer border border-indigo-500/20 text-sm mt-2">
|
|
เข้าสู่ระบบ <i data-lucide="arrow-right" class="w-4 h-4"></i>
|
|
</button>
|
|
</form>
|
|
|
|
<div class="mt-8 text-center border-t border-slate-50 pt-4">
|
|
<p class="text-[10px] font-bold text-slate-400">สำหรับความปลอดภัย ข้อมูลการทำงานจะถูกบันทึกในระบบบัญชี</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|