revise backend

This commit is contained in:
Michal Sedlák
2026-10-18 15:55:34 +02:00
parent dc452059f3
commit 99b1c96f4b
23 changed files with 681 additions and 720 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
/** Shared session checks. Database, form and session keys retain their legacy names. */
function requireLogin(string $loginUrl): void {
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
if (!isset($_SESSION['uname'])) {
header('Location: ' . $loginUrl);
exit;
}
}
function hasPermission(string $permission): bool {
return !empty($_SESSION[$permission]);
}
function requirePermission(string $permission, string $message): void {
if (!hasPermission($permission)) {
http_response_code(403);
exit($message);
}
}
function isPasswordValid(string $password): bool {
return strlen($password) >= 8
&& preg_match('/[0-9]/', $password) === 1
&& preg_match('/[A-Z]/', $password) === 1;
}