117 lines
3.6 KiB
PHP
117 lines
3.6 KiB
PHP
<?php
|
|
// login.php
|
|
require_once 'db/config.php';
|
|
|
|
if (isset($_SESSION['user_id'])) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = $_POST['username'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if ($username && $password) {
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE username = ? AND deleted_at IS NULL");
|
|
$stmt->execute([$username]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
$_SESSION['full_name'] = $user['full_name'];
|
|
$_SESSION['role'] = $user['role'];
|
|
|
|
header("Location: index.php");
|
|
exit;
|
|
} else {
|
|
$error = "Invalid username or password.";
|
|
}
|
|
} else {
|
|
$error = "Please enter both username and password.";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login - CRM System</title>
|
|
<!-- Inter Font -->
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<!-- Bootstrap 5 -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
font-family: 'Inter', sans-serif;
|
|
background-color: #f9fafb;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100vh;
|
|
margin: 0;
|
|
}
|
|
.login-card {
|
|
width: 100%;
|
|
max-width: 400px;
|
|
padding: 2rem;
|
|
background: #ffffff;
|
|
border: 1px solid #e5e7eb;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
|
}
|
|
.brand {
|
|
font-weight: 700;
|
|
font-size: 1.5rem;
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
color: #111827;
|
|
}
|
|
.btn-primary {
|
|
background-color: #111827;
|
|
border-color: #111827;
|
|
width: 100%;
|
|
padding: 0.75rem;
|
|
font-weight: 600;
|
|
}
|
|
.btn-primary:hover {
|
|
background-color: #1f2937;
|
|
border-color: #1f2937;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-card">
|
|
<div class="brand">CRM PRO</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger py-2 small"><?= e($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="login.php">
|
|
<div class="mb-3">
|
|
<label for="username" class="form-label small fw-bold">Username</label>
|
|
<input type="text" class="form-control" id="username" name="username" required autofocus>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label small fw-bold">Password</label>
|
|
<input type="password" class="form-control" id="password" name="password" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary mt-2">Sign In</button>
|
|
</form>
|
|
|
|
<div class="mt-4 text-center text-muted small">
|
|
<p>Demo Credentials:<br>
|
|
admin / admin<br>
|
|
sales / sales<br>
|
|
finance / finance</p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|