Massive refactor of code into classes, improve security on the image/file upload handler. Clean up the init.php into a config.php and refactor everything else to work around it.

Resolves issues #13 #14 and #16
This commit is contained in:
Andy Dixon
2024-11-12 21:20:46 +00:00
parent 5a02c25074
commit e7373477c5
13 changed files with 581 additions and 242 deletions
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace NeoCMS;
class Authentication
{
private $credentials;
public function __construct(array $credentials)
{
session_start();
$this->credentials = $credentials;
}
/**
* Logs a user into the CMS
* @param $username
* @param $password
* @return bool
*/
public function login($username, $password)
{
if (!empty($this->credentials[$username]) && $this->credentials[$username] === $password) {
$_SESSION['loggedIn'] = true;
$_SESSION['loggedInUser'] = $username;
return true;
}
$_SESSION['loggedIn'] = false;
return false;
}
/**
* Checks if a user has logged in
* @return bool
*/
public function isLoggedIn(): bool
{
return $_SESSION['loggedIn'] ?? false;
}
/**
* Returns the user logged in
* @return string
*/
public function getLoggedInUser(): string
{
return $_SESSION['loggedInUser'] ?? 'Not logged in';
}
/**
* Destroy the session
* @return void
*/
public function logout()
{
session_destroy();
}
}