124 lines
5.3 KiB
PHP
124 lines
5.3 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
if (isLoggedIn()) {
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = $_POST['username'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($username) || empty($password)) {
|
|
$error = 'กรุณากรอกชื่อผู้ใช้และรหัสผ่าน';
|
|
} else {
|
|
$stmt = $pdo->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['role'] = $user['role'];
|
|
$_SESSION['name'] = $user['name'];
|
|
$_SESSION['login_notified'] = false; // Flag for showing popup once
|
|
|
|
logActivity($pdo, 'LOGIN_SUCCESS', "User logged in successfully");
|
|
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
} else {
|
|
$error = 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง';
|
|
// Log failed attempt without a session
|
|
$ip = $_SERVER['REMOTE_ADDR'] ?? 'Unknown';
|
|
try {
|
|
$stmt_log = $pdo->prepare("INSERT INTO activity_logs (user_id, action, details, ip_address) VALUES (NULL, 'LOGIN_FAILED', ?, ?)");
|
|
$stmt_log->execute(["Attempt with username: $username", $ip]);
|
|
} catch (Exception $e) {}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="th">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>เข้าสู่ระบบ - ระบบแจ้งเตือนส่งงาน</title>
|
|
<link rel="icon" type="image/png" href="assets/img/logo.png">
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<style>
|
|
body { font-family: 'Sarabun', sans-serif; }
|
|
|
|
.shiny-logo {
|
|
position: relative;
|
|
overflow: hidden;
|
|
display: inline-block;
|
|
border-radius: 50%; /* Adjust depending on logo shape */
|
|
}
|
|
|
|
.shiny-logo::after {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
left: -150%;
|
|
width: 50%;
|
|
height: 100%;
|
|
background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.7) 50%, rgba(255,255,255,0) 100%);
|
|
transform: skewX(-25deg);
|
|
animation: shine 6s infinite ease-in-out;
|
|
}
|
|
|
|
@keyframes shine {
|
|
0% { left: -150%; }
|
|
15% { left: 200%; }
|
|
100% { left: 200%; } /* Long pause before shining again */
|
|
}
|
|
</style>
|
|
<link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
|
</head>
|
|
<body class="bg-gray-100 flex items-center justify-center h-screen">
|
|
|
|
<div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md">
|
|
<div class="text-center mb-8">
|
|
<div class="shiny-logo mb-4">
|
|
<img src="assets/img/logo.png" alt="Logo" class="w-24 h-24 object-contain">
|
|
</div>
|
|
<h1 class="text-2xl font-bold text-gray-800">ระบบแจ้งเตือนส่งงาน</h1>
|
|
<p class="text-gray-500 text-sm mt-2">เข้าสู่ระบบเพื่อจัดการและดูงานของคุณ</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4" role="alert">
|
|
<span class="block sm:inline"><?= htmlspecialchars($error) ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="">
|
|
<div class="mb-4">
|
|
<label for="username" class="block text-gray-700 text-sm font-bold mb-2"><i class="fas fa-user mr-2"></i>ชื่อผู้ใช้</label>
|
|
<input type="text" id="username" name="username" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:ring-2 focus:ring-blue-500" required>
|
|
</div>
|
|
|
|
<div class="mb-6">
|
|
<label for="password" class="block text-gray-700 text-sm font-bold mb-2"><i class="fas fa-lock mr-2"></i>รหัสผ่าน</label>
|
|
<input type="password" id="password" name="password" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 mb-3 leading-tight focus:outline-none focus:ring-2 focus:ring-blue-500" required>
|
|
</div>
|
|
|
|
<div class="flex items-center justify-between">
|
|
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline w-full transition duration-300">
|
|
<i class="fas fa-sign-in-alt mr-2"></i> เข้าสู่ระบบ
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|