CoffreFortV1.1
This commit is contained in:
parent
f29fa66d41
commit
d63ebb2066
11
db/migrations/001_create_users_table.sql
Normal file
11
db/migrations/001_create_users_table.sql
Normal file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(50) NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`email` varchar(100) NOT NULL,
|
||||
`role` enum('Admin','User/Member','Viewer','Auditor') NOT NULL DEFAULT 'User/Member',
|
||||
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `username` (`username`),
|
||||
UNIQUE KEY `email` (`email`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<?php if (session_status() == PHP_SESSION_NONE) { session_start(); } ?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@ -42,9 +42,18 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.php#contact">Contact</a>
|
||||
</li>
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-lg-2" href="#">Login</a>
|
||||
<a class="nav-link" href="#">Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-lg-2" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-lg-2" href="login.php">Login</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
73
index.php
73
index.php
@ -1,17 +1,62 @@
|
||||
<?php include 'includes/header.php'; ?>
|
||||
|
||||
<!-- Hero Section -->
|
||||
<header class="hero text-center">
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
|
||||
<div class="container mt-5 pt-5">
|
||||
<h1 class="display-5">Welcome to your Dashboard, <?php echo htmlspecialchars($_SESSION['username']); ?>!</h1>
|
||||
<p class="lead">This is your private area. More features will be added soon.</p>
|
||||
|
||||
<?php if ($_SESSION['role'] === 'Admin'): ?>
|
||||
<div class="alert alert-info">
|
||||
You are logged in as an <strong>Admin</strong>. You have full access to the system.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row mt-5">
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Documents</h5>
|
||||
<p class="card-text">Manage your documents here.</p>
|
||||
<a href="#" class="btn btn-primary">Go to Documents</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Users</h5>
|
||||
<p class="card-text">Manage users here.</p>
|
||||
<a href="#" class="btn btn-primary">Go to Users</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Settings</h5>
|
||||
<p class="card-text">System settings.</p>
|
||||
<a href="#" class="btn btn-primary">Go to Settings</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<!-- Hero Section -->
|
||||
<header class="hero text-center">
|
||||
<div class="container">
|
||||
<h1 class="display-3 fw-bold">Securely Share Your Documents</h1>
|
||||
<p class="lead my-4">A professional, simple, and secure platform for sharing files with your team and clients.</p>
|
||||
<a href="#contact" class="btn btn-primary btn-lg">Get Started</a>
|
||||
<a href="#" class="btn btn-secondary btn-lg">Login</a>
|
||||
<a href="login.php" class="btn btn-secondary btn-lg">Login</a>
|
||||
</div>
|
||||
</header>
|
||||
</header>
|
||||
|
||||
<!-- About Section -->
|
||||
<section id="about" class="section bg-white">
|
||||
<!-- About Section -->
|
||||
<section id="about" class="section bg-white">
|
||||
<div class="container">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-lg-6">
|
||||
@ -24,10 +69,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<!-- Features Section -->
|
||||
<section id="features" class="section">
|
||||
<!-- Features Section -->
|
||||
<section id="features" class.section">
|
||||
<div class="container">
|
||||
<div class="text-center mb-5">
|
||||
<h2 class="fw-bold">Features Designed for Security and Ease of Use</h2>
|
||||
@ -63,10 +108,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<!-- Contact Section -->
|
||||
<section id="contact" class="section bg-white">
|
||||
<!-- Contact Section -->
|
||||
<section id="contact" class="section bg-white">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-8 mx-auto text-center">
|
||||
@ -101,6 +146,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
62
login.php
Normal file
62
login.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
$error = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
if (empty($_POST['username']) || empty($_POST['password'])) {
|
||||
$error = 'Username and password are required.';
|
||||
} else {
|
||||
try {
|
||||
$stmt = db()->prepare("SELECT * FROM users WHERE username = ?");
|
||||
$stmt->execute([$_POST['username']]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($_POST['password'], $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
$_SESSION['role'] = $user['role'];
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
} else {
|
||||
$error = 'Invalid credentials.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$error = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include 'includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4>Login</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
<form action="login.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
7
logout.php
Normal file
7
logout.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user