Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac58933e42 | ||
|
|
14c0118747 | ||
|
|
1f29b92655 | ||
|
|
c6fdd282f8 |
160
assets/css/custom.css
Normal file
160
assets/css/custom.css
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
body {
|
||||||
|
font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
|
||||||
|
background-color: #F4F7F6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 250px;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
padding-top: 1rem;
|
||||||
|
border-right: 1px solid #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link {
|
||||||
|
color: #333;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link.active,
|
||||||
|
.sidebar .nav-link:hover {
|
||||||
|
color: #4A90E2;
|
||||||
|
background-color: #e9f2fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link .feather {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
margin-left: 250px;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-card {
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||||
|
transition: transform 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-card:hover {
|
||||||
|
transform: translateY(-5px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-card .card-img-top {
|
||||||
|
border-top-left-radius: 8px;
|
||||||
|
border-top-right-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* New styles for login/register form */
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-container {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 400px;
|
||||||
|
padding: 2rem;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-container h2 {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
color: #555;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
button[type="submit"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: #4A90E2;
|
||||||
|
color: white;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
button[type="submit"]:hover {
|
||||||
|
background-color: #357ABD;
|
||||||
|
}
|
||||||
|
|
||||||
|
.errors {
|
||||||
|
background-color: #f8d7da;
|
||||||
|
color: #721c24;
|
||||||
|
padding: 1rem;
|
||||||
|
border: 1px solid #f5c6cb;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-container p {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.success {
|
||||||
|
background-color: #d4edda;
|
||||||
|
color: #155724;
|
||||||
|
padding: 1rem;
|
||||||
|
border: 1px solid #c3e6cb;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.sidebar {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
position: relative;
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav {
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
margin-left: 0;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-container {
|
||||||
|
padding: 1.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
4
assets/js/main.js
Normal file
4
assets/js/main.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
// Future JavaScript will go here
|
||||||
|
});
|
||||||
3
auth_footer.php
Normal file
3
auth_footer.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
10
auth_header.php
Normal file
10
auth_header.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Water Tank Monitoring</title>
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
39
db/migrate.php
Normal file
39
db/migrate.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/config.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
echo "Connected to database.\n";
|
||||||
|
|
||||||
|
// 1. Create migrations table if it doesn't exist
|
||||||
|
$migrationTableSql = file_get_contents(__DIR__ . '/migrations/000_create_migrations_table.sql');
|
||||||
|
$pdo->exec($migrationTableSql);
|
||||||
|
echo "Migrations table ensured.\n";
|
||||||
|
|
||||||
|
// 2. Get executed migrations
|
||||||
|
$stmt = $pdo->query("SELECT migration FROM migrations");
|
||||||
|
$executedMigrations = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
// 3. Find and execute new migrations
|
||||||
|
$migrationFiles = glob(__DIR__ . '/migrations/*.sql');
|
||||||
|
sort($migrationFiles);
|
||||||
|
|
||||||
|
foreach ($migrationFiles as $file) {
|
||||||
|
$migrationName = basename($file);
|
||||||
|
if (!in_array($migrationName, $executedMigrations)) {
|
||||||
|
$sql = file_get_contents($file);
|
||||||
|
$pdo->exec($sql);
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||||
|
$stmt->execute([$migrationName]);
|
||||||
|
|
||||||
|
echo "Executed migration: $migrationName\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "All migrations have been run.\n";
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Database migration failed: " . $e->getMessage() . "\n");
|
||||||
|
}
|
||||||
|
|
||||||
5
db/migrations/000_create_migrations_table.sql
Normal file
5
db/migrations/000_create_migrations_table.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `migrations` (
|
||||||
|
`id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`migration` VARCHAR(255) NOT NULL,
|
||||||
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
8
db/migrations/001_create_users_table.sql
Normal file
8
db/migrations/001_create_users_table.sql
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `users` (
|
||||||
|
`id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`username` VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
`email` VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
`password` VARCHAR(255) NOT NULL,
|
||||||
|
`role` VARCHAR(50) NOT NULL DEFAULT 'user',
|
||||||
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
17
db/setup_db.php
Normal file
17
db/setup_db.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
// Generated by setup_mariadb_project.sh — edit as needed.
|
||||||
|
define('DB_HOST', '127.0.0.1');
|
||||||
|
define('DB_NAME', 'app_30903');
|
||||||
|
define('DB_USER', 'app_30903');
|
||||||
|
define('DB_PASS', '7d2d5a2d-6e5e-4580-a9b7-3f8e7288a494');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
]);
|
||||||
|
$pdo->exec("CREATE DATABASE IF NOT EXISTS `".DB_NAME."`");
|
||||||
|
echo "Database `".DB_NAME."` created or already exists.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Database setup failed: " . $e->getMessage() . "\n");
|
||||||
|
}
|
||||||
|
|
||||||
5
footer.php
Normal file
5
footer.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
feather.replace();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
22
header.php
Normal file
22
header.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protect page
|
||||||
|
if (!isset($_SESSION['user_id'])) {
|
||||||
|
header('Location: login.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Admin Dashboard - Water Tank Monitoring</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
179
index.php
179
index.php
@ -1,131 +1,58 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
include 'header.php';
|
||||||
@ini_set('display_errors', '1');
|
|
||||||
@error_reporting(E_ALL);
|
|
||||||
@date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
$phpVersion = PHP_VERSION;
|
// Admin only page
|
||||||
$now = date('Y-m-d H:i:s');
|
if ($_SESSION['role'] !== 'admin') {
|
||||||
|
// You can redirect to a different page for non-admin users
|
||||||
|
// For now, just show an error or redirect to login
|
||||||
|
header('Location: login.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
<?php include 'sidebar.php'; ?>
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
<div class="main-content">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<title>New Style</title>
|
<h2>Dashboard</h2>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<div class="d-flex align-items-center">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<span class="me-3">Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>!</span>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--bg-color-start: #6a11cb;
|
|
||||||
--bg-color-end: #2575fc;
|
|
||||||
--text-color: #ffffff;
|
|
||||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
|
||||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
|
||||||
color: var(--text-color);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
body::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
|
||||||
animation: bg-pan 20s linear infinite;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
@keyframes bg-pan {
|
|
||||||
0% { background-position: 0% 0%; }
|
|
||||||
100% { background-position: 100% 100%; }
|
|
||||||
}
|
|
||||||
main {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
.card {
|
|
||||||
background: var(--card-bg-color);
|
|
||||||
border: 1px solid var(--card-border-color);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 2rem;
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
-webkit-backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
.loader {
|
|
||||||
margin: 1.25rem auto 1.25rem;
|
|
||||||
width: 48px;
|
|
||||||
height: 48px;
|
|
||||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
|
||||||
border-top-color: #fff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
from { transform: rotate(0deg); }
|
|
||||||
to { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
.hint {
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px; height: 1px;
|
|
||||||
padding: 0; margin: -1px;
|
|
||||||
overflow: hidden;
|
|
||||||
clip: rect(0, 0, 0, 0);
|
|
||||||
white-space: nowrap; border: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 3rem;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 1rem;
|
|
||||||
letter-spacing: -1px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background: rgba(0,0,0,0.2);
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<main>
|
|
||||||
<div class="card">
|
|
||||||
<h1>Analyzing your requirements and generating your website…</h1>
|
|
||||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
|
||||||
<span class="sr-only">Loading…</span>
|
|
||||||
</div>
|
</div>
|
||||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWiZZy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
</header>
|
||||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
|
||||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card summary-card">
|
||||||
|
<img src="https://picsum.photos/seed/users/400/200" class="card-img-top" alt="Abstract representation of user profiles.">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Total Users</h5>
|
||||||
|
<p class="card-text">A brief overview of user statistics.</p>
|
||||||
|
<a href="#" class="btn btn-primary" style="background-color: #4A90E2;">Manage Users</a>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</div>
|
||||||
<footer>
|
</div>
|
||||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
<div class="col-md-4">
|
||||||
</footer>
|
<div class="card summary-card">
|
||||||
</body>
|
<img src="https://picsum.photos/seed/tanks/400/200" class="card-img-top" alt="Illustration of interconnected tanks.">
|
||||||
</html>
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Tanks Overview</h5>
|
||||||
|
<p class="card-text">Summary of tank statuses and levels.</p>
|
||||||
|
<a href="#" class="btn btn-primary" style="background-color: #4A90E2;">View Tanks</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card summary-card">
|
||||||
|
<img src="https://picsum.photos/seed/devices/400/200" class="card-img-top" alt="Network of connected IoT devices.">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">IoT Devices</h5>
|
||||||
|
<p class="card-text">Status of all connected IoT devices.</p>
|
||||||
|
<a href="#" class="btn btn-primary" style="background-color: #4A90E2;">Manage Devices</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'footer.php'; ?>
|
||||||
77
login.php
Normal file
77
login.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If user is already logged in, redirect to dashboard
|
||||||
|
if (isset($_SESSION['user_id'])) {
|
||||||
|
header('Location: index.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$message = $_SESSION['message'] ?? null;
|
||||||
|
unset($_SESSION['message']);
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$email = $_POST['email'] ?? '';
|
||||||
|
$password = $_POST['password'] ?? '';
|
||||||
|
|
||||||
|
if (empty($email)) {
|
||||||
|
$errors[] = 'Email is required';
|
||||||
|
}
|
||||||
|
if (empty($password)) {
|
||||||
|
$errors[] = 'Password is required';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
|
||||||
|
$stmt->execute([$email]);
|
||||||
|
$user = $stmt->fetch();
|
||||||
|
|
||||||
|
if ($user && password_verify($password, $user['password'])) {
|
||||||
|
$_SESSION['user_id'] = $user['id'];
|
||||||
|
$_SESSION['username'] = $user['username'];
|
||||||
|
$_SESSION['role'] = $user['role'];
|
||||||
|
header('Location: index.php');
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$errors[] = 'Invalid email or password';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<?php include 'auth_header.php'; ?>
|
||||||
|
|
||||||
|
<div class="form-container">
|
||||||
|
<h2>Login</h2>
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<div class="success">
|
||||||
|
<p><?php echo htmlspecialchars($message); ?></p>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($errors)): ?>
|
||||||
|
<div class="errors">
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<p><?php echo htmlspecialchars($error); ?></p>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<form action="login.php" method="post">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input type="email" name="email" id="email" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" name="password" id="password" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
</form>
|
||||||
|
<p>Don't have an account? <a href="register.php">Register here</a>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'auth_footer.php'; ?>
|
||||||
14
logout.php
Normal file
14
logout.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unset all of the session variables
|
||||||
|
$_SESSION = [];
|
||||||
|
|
||||||
|
// Destroy the session.
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
// Redirect to login page
|
||||||
|
header('Location: login.php');
|
||||||
|
exit;
|
||||||
98
register.php
Normal file
98
register.php
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
// Start session
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$success = '';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$username = $_POST['username'] ?? '';
|
||||||
|
$email = $_POST['email'] ?? '';
|
||||||
|
$password = $_POST['password'] ?? '';
|
||||||
|
$password_confirm = $_POST['password_confirm'] ?? '';
|
||||||
|
|
||||||
|
if (empty($username)) {
|
||||||
|
$errors[] = 'Username is required';
|
||||||
|
}
|
||||||
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$errors[] = 'Invalid email format';
|
||||||
|
}
|
||||||
|
if (empty($email)) {
|
||||||
|
$errors[] = 'Email is required';
|
||||||
|
}
|
||||||
|
if (strlen($password) < 8) {
|
||||||
|
$errors[] = 'Password must be at least 8 characters long';
|
||||||
|
}
|
||||||
|
if (empty($password)) {
|
||||||
|
$errors[] = 'Password is required';
|
||||||
|
}
|
||||||
|
if ($password !== $password_confirm) {
|
||||||
|
$errors[] = 'Passwords do not match';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
|
||||||
|
$stmt->execute([$username, $email]);
|
||||||
|
if ($stmt->fetch()) {
|
||||||
|
$errors[] = 'Username or email already exists';
|
||||||
|
} else {
|
||||||
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
// For now, the first registered user will be an admin
|
||||||
|
$role = 'user';
|
||||||
|
$stmt_count = $pdo->query("SELECT COUNT(*) FROM users");
|
||||||
|
$user_count = $stmt_count->fetchColumn();
|
||||||
|
if ($user_count === 0) {
|
||||||
|
$role = 'admin';
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, ?)");
|
||||||
|
if ($stmt->execute([$username, $email, $hashed_password, $role])) {
|
||||||
|
$_SESSION['message'] = 'Registration successful! Please login.';
|
||||||
|
header('Location: login.php');
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$errors[] = 'Failed to register user';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<?php include 'auth_header.php'; ?>
|
||||||
|
|
||||||
|
<div class="form-container">
|
||||||
|
<h2>Register</h2>
|
||||||
|
<?php if (!empty($errors)): ?>
|
||||||
|
<div class="errors">
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<p><?php echo htmlspecialchars($error); ?></p>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<form action="register.php" method="post" novalidate>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input type="text" name="username" id="username" value="<?php echo isset($_POST['username']) ? htmlspecialchars($_POST['username']) : ''; ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input type="email" name="email" id="email" value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" name="password" id="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password_confirm">Confirm Password</label>
|
||||||
|
<input type="password" name="password_confirm" id="password_confirm" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit">Register</button>
|
||||||
|
</form>
|
||||||
|
<p>Already have an account? <a href="login.php">Login here</a>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'auth_footer.php'; ?>
|
||||||
35
sidebar.php
Normal file
35
sidebar.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<div class="sidebar">
|
||||||
|
<h4 class="px-3">TankMon</h4>
|
||||||
|
<ul class="nav flex-column">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" href="index.php">
|
||||||
|
<i data-feather="home"></i>
|
||||||
|
Dashboard
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="users.php">
|
||||||
|
<i data-feather="users"></i>
|
||||||
|
Users
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">
|
||||||
|
<i data-feather="database"></i>
|
||||||
|
Tanks
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">
|
||||||
|
<i data-feather="hard-drive"></i>
|
||||||
|
IoT Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">
|
||||||
|
<i data-feather="settings"></i>
|
||||||
|
Settings
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
68
users.php
Normal file
68
users.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
require_once 'header.php';
|
||||||
|
|
||||||
|
// Check if user is logged in and is an admin
|
||||||
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'admin') {
|
||||||
|
echo '<div class="container">
|
||||||
|
<div class="alert alert-danger mt-5" role="alert">
|
||||||
|
You are not authorized to view this page. Please <a href="login.php">login</a> as an admin.
|
||||||
|
</div>
|
||||||
|
</div>';
|
||||||
|
require_once 'footer.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch users from the database
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT id, name, email, role, created_at FROM users ORDER BY created_at DESC');
|
||||||
|
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
include 'sidebar.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h2>User Management</h2>
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<span class="me-3">Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>!</span>
|
||||||
|
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Role</th>
|
||||||
|
<th>Registered At</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($users)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="5" class="text-center">No users found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($users as $user): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($user['id']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($user['name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($user['email']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($user['role']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars(date('Y-m-d H:i', strtotime($user['created_at']))); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'footer.php';
|
||||||
|
?>
|
||||||
Loading…
x
Reference in New Issue
Block a user