a bunch of stuff happened. I'll do better next commit...

This commit is contained in:
2026-10-09 08:24:28 -04:00
parent bf8ad6a858
commit 4bceed7cb9
27 changed files with 540 additions and 112 deletions
+60 -29
View File
@@ -13,8 +13,8 @@ class Base {
// Constants
// =========
const APPLICATION_NAME = "BaseProject";
const APPLICATION_MNEMONIC = "BASEPROJECT";
const APPLICATION_NAME = "DEC Authentication Service";
const APPLICATION_MNEMONIC = "DECAUTHY";
const VERSION = "1.00";
const TIMEZONE = "America/New_York";
@@ -22,22 +22,22 @@ class Base {
// Session Variables
// =================
const ENVIRONMENT = "BASEPROJECT_ENVIRONMENT";
const ACTIVE_SESSION = "BASEPROJECT_ACTIVE_SESSION";
const USER_SERIAL = "BASEPROJECT_USER_SERIAL";
const USER_NAME = "BASEPROJECT_USER_NAME";
const USER_FULL_NAME = "BASEPROJECT_USER_FULL_NAME";
const USER_EMAIL = "BASEPROJECT_USER_EMAIL";
const USER_ROLE = "BASEPROJECT_USER_ROLE";
const USER_AUTHENTICATED = "BASEPROJECT_USER_AUTHENTICATED";
const REPORTS_GET = "BASEPROJECT_REPORTS_GET";
const REPORTS_POST = "BASEPROJECT_REPORTS_POST";
const THEME = "BASEPROJECT_THEME";
const AJAX = "BASEPROJECT_AJAX";
const TODAY = "BASEPROJECT_TODAY";
const COPYRIGHT = "BASEPROJECT_COPYRIGHT";
const PAGE = "BASEPROJECT_PAGE";
const PAGINATION_PAGE = "BASEPROJECT_PAGINATION_PAGE";
const ENVIRONMENT = "DECAUTHY_ENVIRONMENT";
const ACTIVE_SESSION = "DECAUTHY_ACTIVE_SESSION";
const USER_SERIAL = "DECAUTHY_USER_SERIAL";
const USER_NAME = "DECAUTHY_USER_NAME";
const USER_FULL_NAME = "DECAUTHY_USER_FULL_NAME";
const USER_EMAIL = "DECAUTHY_USER_EMAIL";
const USER_ROLE = "DECAUTHY_USER_ROLE";
const USER_AUTHENTICATED = "DECAUTHY_USER_AUTHENTICATED";
const REPORTS_GET = "DECAUTHY_REPORTS_GET";
const REPORTS_POST = "DECAUTHY_REPORTS_POST";
const THEME = "DECAUTHY_THEME";
const AJAX = "DECAUTHY_AJAX";
const TODAY = "DECAUTHY_TODAY";
const COPYRIGHT = "DECAUTHY_COPYRIGHT";
const PAGE = "DECAUTHY_PAGE";
const PAGINATION_PAGE = "DECAUTHY_PAGINATION_PAGE";
// =================
// Class Constructor
@@ -93,6 +93,8 @@ class Base {
$XSLParms["TODAY_MMDDYYYY"] = date("m/d/Y");
$XSLParms["TODAY_HHMM"] = date("Hi");
$XSLParms["COPYRIGHT"] = date("Y");
$_SESSION['DECAUTHY_CSRF'] ??= bin2hex(random_bytes(32));
$XSLParms['CSRF_TOKEN'] = $_SESSION['DECAUTHY_CSRF'];
$XML = new DOMDocument();
$XSL = new DOMDocument();
@@ -257,8 +259,7 @@ class Base {
public function displayHome() {
$content = $this->applyXSL("", $this->getXSL("home"));
$this->displayContent($content);
(new Applications())->dashboard();
}
// =======================
@@ -276,6 +277,14 @@ class Base {
$action = (empty($Xaction) ? $action : $Xaction);
if (strtolower(trim($action)) === 'signout') {
$_SESSION = [];
session_regenerate_id(true);
$this->initializeSession();
header('Location: main.php');
exit();
}
if ($Xaction == 'resetpassword') {
$this->resetpassword();
}
@@ -289,7 +298,7 @@ class Base {
// Determine if user needs a password change
if ($this->userChangePassword() === true) {
(new Users())->changePassword();
(new Users())->changePassword($action !== 'Users.changePassword');
exit();
}
@@ -304,16 +313,19 @@ class Base {
$action = (empty($Xaction) ? $action : $Xaction);
// Sign Out if requested.
if (strtolower(trim($action)) === "signout") {
$this->initializeSession();
}
// Process the requested Action.
list($class, $method) = array_pad(explode('.', $action), 2, "");
if (strcasecmp($class, 'Applications') === 0 && !in_array(strtolower($method), ['dashboard', 'manageaccess', 'saveaccess', 'launch', 'setup'], true)) {
http_response_code(404);
exit('Unknown application action.');
}
// Account management can change roles, so enforce its administrator boundary here as well.
if (strcasecmp($class, 'Users') === 0 && strcasecmp($method, 'changePassword') !== 0) {
(new Applications())->authorizeAdministration();
}
if (empty($method)) {
$method = $class;
@@ -745,7 +757,7 @@ class Base {
$password = '';
for ($i = 0; $i < $length; $i++) {
$index = rand(0, strlen($characters) - 1);
$index = random_int(0, strlen($characters) - 1);
$password .= $characters[$index];
}
@@ -760,6 +772,13 @@ class Base {
$user = (new Users())->getUserByUserName($_SESSION[self::USER_NAME]);
if ($user->count() === 0 || (string) $user->record->user_status !== 'active') {
$_SESSION = [];
session_regenerate_id(true);
header('Location: main.php');
exit();
}
if ($user->record->user_change_password == 1) {
return true;
@@ -802,16 +821,28 @@ class Base {
public function resetPassword() {
if (!$this->validAuthRequest()) {
http_response_code(403);
exit('Invalid authentication request. Reload the sign-in page.');
}
require_once 'classes/Authentication.php';
$XSLParms = [
"BTN_SUBMIT" => "main.php?action=Users.signIn&step=authenticate",
"BTN_SUBMIT" => "main.php",
"RESET_PASSWORD_SUCCESSFUL" => (new Authentication())->resetPassword() ? "TRUE" : "FALSE"
];
echo $this->applyXSL("", $this->getXSL("signIn"), $XSLParms);
exit;
}
public function validAuthRequest(): bool {
$token = filter_input(INPUT_POST, 'csrf_token') ?: '';
return ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST'
&& isset($_SESSION['DECAUTHY_CSRF'])
&& hash_equals($_SESSION['DECAUTHY_CSRF'], $token);
}
}
?>