35583-vm/login.php
Flatlogic Bot 58e3bb7010 1.2
2025-11-09 03:37:51 +00:00

97 lines
3.3 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'includes/functions.php';
start_secure_session();
// If user is already logged in, redirect to dashboard
if (is_logged_in()) {
header('Location: /index.php');
exit();
}
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($username) || empty($password)) {
$error_message = 'Please enter both username and password.';
} else {
$user = get_user_by_username($username);
if ($user && password_verify($password, $user['password'])) {
// Password is correct, so start a new session
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['role'] = $user['role'];
// Redirect to user dashboard page
header('Location: /index.php');
exit();
} else {
// Password is not correct
$error_message = 'Invalid username or password.';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - RedSolutions CRM</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<style>
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f8f9fa;
}
.login-card {
width: 100%;
max-width: 400px;
padding: 2rem;
}
</style>
</head>
<body>
<div class="card login-card shadow-sm">
<div class="card-body">
<div class="text-center mb-4">
<i class="bi bi-buildings me-2 fs-2"></i>
<h1 class="h3 mb-3 fw-normal">RedSolutions CRM</h1>
<p>Please sign in to continue</p>
</div>
<?php if (!empty($error_message)): ?>
<div class="alert alert-danger" role="alert">
<?php echo $error_message; ?>
</div>
<?php endif; ?>
<form action="login.php" method="POST">
<div class="form-floating mb-3">
<input type="text" class="form-control" id="username" name="username" placeholder="Username" required>
<label for="username">Username</label>
</div>
<div class="form-floating mb-3">
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
<label for="password">Password</label>
</div>
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
</form>
<p class="mt-5 mb-3 text-muted text-center">&copy; <?php echo date('Y'); ?> Flatlogic</p>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>