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">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
@ -42,9 +42,18 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="index.php#contact">Contact</a>
|
<a class="nav-link" href="index.php#contact">Contact</a>
|
||||||
</li>
|
</li>
|
||||||
|
<?php if (isset($_SESSION['user_id'])): ?>
|
||||||
<li class="nav-item">
|
<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>
|
||||||
|
<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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
51
index.php
51
index.php
@ -1,12 +1,57 @@
|
|||||||
<?php include 'includes/header.php'; ?>
|
<?php include 'includes/header.php'; ?>
|
||||||
|
|
||||||
|
<?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 -->
|
<!-- Hero Section -->
|
||||||
<header class="hero text-center">
|
<header class="hero text-center">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="display-3 fw-bold">Securely Share Your Documents</h1>
|
<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>
|
<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="#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>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@ -27,7 +72,7 @@
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<!-- Features Section -->
|
<!-- Features Section -->
|
||||||
<section id="features" class="section">
|
<section id="features" class.section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="text-center mb-5">
|
<div class="text-center mb-5">
|
||||||
<h2 class="fw-bold">Features Designed for Security and Ease of Use</h2>
|
<h2 class="fw-bold">Features Designed for Security and Ease of Use</h2>
|
||||||
@ -103,4 +148,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php include 'includes/footer.php'; ?>
|
<?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