New admins pages

This commit is contained in:
2024-12-10 11:09:39 +01:00
parent 5ae6f24bbd
commit 4fa387e8af
6 changed files with 214 additions and 0 deletions

49
1-login.css Normal file
View File

@@ -0,0 +1,49 @@
/* (A) WHOLE PAGE */
* {
font-family: Arial, Helvetica, sans-serif;
box-sizing: border-box;
}
body {
max-width: 500px;
margin: 0 auto;
padding: 20px;
background: #f7f7f7;
}
/* (B) LOGIN FORM */
#login-form {
padding: 20px;
border: 1px solid #ebebeb;
background: #fff;
}
#login-form h1 {
font-size: 1.5em;
margin: 0 0 20px 0;
}
#login-form label, #login-form input {
display: block;
width: 100%;
margin-top: 10px;
}
#login-form label { color: #767676; }
#login-form input {
padding: 10px;
border: 1px solid #adadad;
}
#login-form input[type=submit] {
margin-top: 20px;
border: 0;
color: #fff;
background: #a52323;
cursor: pointer;
}
/* (C) INVALID LOGIN */
#login-bad {
padding : 10px;
margin-bottom: 20px;
background: #ffe7e7;
border: 1px solid #ff3e3e;
color: #c10000;
font-weight: bold;
}

38
1-login.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
// https://code-boxx.com/simple-php-login-without-database/
// (A) LOGIN CHECKS
require "2-check.php";
include 'localize.php';
$domain = 'sentier';
localize($domain);
include 'functions.php';
// (B) LOGIN PAGE HTML ?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo gettext("Login Page"); ?></title>
<link rel="stylesheet" href="1-login.css" />
<link rel="stylesheet" href="css/sls.css" />
</head>
<body>
<?php if (isset($failed)) { ?>
<div id="login-bad"><?php echo gettext("Invalid email or password."); ?></div>
<?php } ?>
<form id="login-form" method="post" target="_self">
<h1><?php echo gettext("PLEASE SIGN IN"); ?></h1>
<label for="user"><?php echo gettext("User"); ?></label>
<input type="text" name="user" required>
<label for="password"><?php echo gettext("Password"); ?></label>
<input type="password" name="password" required>
<input type="submit" value="<?php echo gettext("Sign In"); ?>">
</form>
<p class="navPage"><a href="index.php" title="<?php echo gettext("Home"); ?>"><?php echo gettext("Home"); ?></a> | <a href="photo-du-mois.php" title="<?php echo gettext("Picture of the month"); ?>"><?php echo gettext("Picture of the month"); ?></a> | <a href="maps.php" title="<?php echo gettext("Maps"); ?>"><?php echo gettext("Maps"); ?></a> | <a href="admin.php" title="<?php echo gettext("Admin page"); ?>"><?php echo gettext("Admin page"); ?></a></p>
<p><em><small>&copy; 2013-<?php echo date('Y'); ?> sur-le-sentier.fr</small></em></p>
</body>
</html>

32
2-check.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
// (A) START SESSION
session_start();
// (B) PROCESS LOGIN
if (isset($_POST["user"]) && !isset($_SESSION["user"])) {
// (B1) USERS & PASSWORDS - SET YOUR OWN !
$users = [
"joe" => "123456",
"jon" => "654321",
"Bruno" => "$2y$10$3yvUbJoB3ZT/H9SdZLxLYuLjFkgbGtlNkfnn2N4IaMvh9gNyZN9d."
];
//echo password_hash("tmyqFG*K-tnMccapTXW3", PASSWORD_DEFAULT);
// (B2) CHECK & VERIFY
if (password_verify($_POST["password"], $users[$_POST["user"]])) {
//if (isset($users[$_POST["user"]]) && $users[$_POST["user"]] == $_POST["password"]) {
$_SESSION["user"] = $_POST["user"];
}
// (B3) FAILED LOGIN FLAG
if (!isset($_SESSION["user"])) { $failed = true; }
}
// (C) REDIRECT TO HOME PAGE IF SIGNED IN - SET YOUR OWN !
if (isset($_SESSION["user"])) {
$page = 'admin.php';
header("Location: $page");
exit();
}

15
3-protect.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
// (A) START SESSION
session_start();
// (B) LOGOUT REQUEST
if (isset($_POST["logout"])) {
session_destroy();
unset($_SESSION);
}
// (C) REDIRECT TO LOGIN PAGE IF NOT SIGNED IN
if (!isset($_SESSION["user"])) {
header("Location: 1-login.php");
exit();
}

6
4-logout.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
session_start(); /* Starts the session */
session_destroy(); /* Destroy started session */
header("location:admin.php"); /* Redirect to login page */
exit;

74
admin.php Normal file
View File

@@ -0,0 +1,74 @@
<?php require ("3-protect.php");
include 'localize.php';
$domain = 'sentier';
localize($domain);
include 'functions.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><?php echo gettext('Logged in'); ?></title>
<link rel="stylesheet" href="css/sls.css" />
<!--link rel='stylesheet' href='css/lc_lightbox.min.css' />
<link rel='stylesheet' href='css/open_close_fx.css' />
<link rel='stylesheet' href='css/minimal.css' /-->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<!--link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script-->
</head>
<body>
<h1><?php echo gettext('Status: ') . $_SESSION["user"] . gettext(' logged in'); ?></h1>
<!--div class="center-flex"-->
<div class="center-flex">
<?php
$base = 'db_photo.sqlite3';
if (file_exists($base)) {
//echo '<div class="base">Base SQLite: ' . $base . ' !</div>';
echo '<h3>Base SQLite: ' . __DIR__ . '/' . $base . ' !</h3>';
}
?>
<nav>
<a class="kaki" href="../edit_bdd.php">Edit</a>
<a class="kaki" href="../insert_bdd.php">Insert</a>
<a class="kaki" href="../modify_bdd.php">Modify</a>
<a class="kaki" href="../view_bdd.php">View (Ajax)</a>
<a class="kaki" href="../view_bdd2.php">View</a>
<a class="kaki" href="../clean_bdd.php">Clean</a>
</nav>
<!-- (B1) LOGOUT FORM -->
<p></p>
<nav><a class="red" href="4-logout.php" role="button">Log out</a></nav>
</div>
<!--form method="post">
<input type="hidden" name="logout" value="1">
<input type="submit" value="Log Out">
</form-->
<?php
//$_SESSION["user"] != ""
?>
<p class="navPage"><a href="index.php" title="<?php echo gettext("Home"); ?>"><?php echo gettext("Home"); ?></a> | <a href="photo-du-mois.php" title="<?php echo gettext("Picture of the month"); ?>"><?php echo gettext("Picture of the month"); ?></a> | <a href="maps.php" title="<?php echo gettext("Maps"); ?>"><?php echo gettext("Maps"); ?></a> | <a href="admin.php" title="<?php echo gettext("Admin page"); ?>"><?php echo gettext("Admin page"); ?></a></p>
<p><em><small>&copy; 2013-<?php echo date('Y'); ?> sur-le-sentier.fr</small></em></p>
</body>
</html>