This commit is contained in:
2026-01-06 10:02:25 +01:00
parent f685c2490a
commit b52d3a11be
111 changed files with 12830 additions and 76 deletions

View File

@@ -0,0 +1,40 @@
{
"name": "codepress/admin-console",
"description": "Admin Console for CodePress CMS",
"type": "project",
"require": {
"php": ">=8.4",
"firebase/php-jwt": "^6.10",
"phpmailer/phpmailer": "^6.9",
"monolog/monolog": "^3.5"
},
"require-dev": {
"phpunit/phpunit": "^11.0",
"squizlabs/php_codesniffer": "^3.10"
},
"autoload": {
"psr-4": {
"CodePress\\Admin\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"CodePress\\Admin\\Tests\\": "tests/"
}
},
"scripts": {
"start": "php -S localhost:8081 -t public",
"test": "phpunit",
"lint": "phpcs --standard=PSR12 src/",
"lint-fix": "phpcbf --standard=PSR12 src/"
},
"license": "MIT",
"authors": [
{
"name": "Edwin Noorlander",
"email": "edwin@noorlander.info"
}
],
"minimum-stability": "stable",
"prefer-stable": true
}

View File

@@ -0,0 +1,57 @@
<?php
return [
'name' => 'CodePress Admin Console',
'version' => '1.0.0',
'debug' => true,
'timezone' => 'Europe/Amsterdam',
// Security
'security' => [
'jwt_secret' => $_ENV['JWT_SECRET'] ?? 'your-secret-key-change-in-production',
'jwt_expiration' => 3600, // 1 hour
'session_timeout' => 1800, // 30 minutes
'max_login_attempts' => 5,
'lockout_duration' => 900, // 15 minutes
],
// Database
'database' => [
'type' => 'sqlite',
'path' => __DIR__ . '/../database/admin.db',
'backup_path' => __DIR__ . '/../storage/backups/',
],
// CodePress Integration
'codepress' => [
'path' => __DIR__ . '/../../',
'content_dir' => __DIR__ . '/../../public/content/',
'templates_dir' => __DIR__ . '/../../engine/templates/',
'plugins_dir' => __DIR__ . '/../../plugins/',
],
// Email
'mail' => [
'host' => $_ENV['MAIL_HOST'] ?? 'localhost',
'port' => $_ENV['MAIL_PORT'] ?? 587,
'username' => $_ENV['MAIL_USERNAME'] ?? '',
'password' => $_ENV['MAIL_PASSWORD'] ?? '',
'from' => $_ENV['MAIL_FROM'] ?? 'admin@codepress.local',
'from_name' => 'CodePress Admin',
],
// Storage
'storage' => [
'uploads_path' => __DIR__ . '/../storage/uploads/',
'logs_path' => __DIR__ . '/../storage/logs/',
'cache_path' => __DIR__ . '/../storage/cache/',
],
// UI Settings
'ui' => [
'theme' => 'bootstrap',
'items_per_page' => 20,
'date_format' => 'd-m-Y H:i',
'timezone' => 'Europe/Amsterdam',
],
];

View File

@@ -0,0 +1,80 @@
<?php
namespace CodePress\Admin\Controllers;
use CodePress\Admin\Services\AuthService;
use CodePress\Admin\Services\LoggerService;
class AuthController {
private AuthService $authService;
private LoggerService $logger;
public function __construct() {
$this->authService = new AuthService();
$this->logger = new LoggerService();
}
public function login() {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
$remember = isset($_POST['remember']);
$result = $this->authService->login($username, $password, $remember);
if ($result['success']) {
$this->logger->info("User logged in: {$username}");
$this->jsonResponse(['success' => true, 'redirect' => '/admin/dashboard']);
} else {
$this->logger->warning("Failed login attempt: {$username}");
$this->jsonResponse(['success' => false, 'message' => $result['message']]);
}
}
$this->renderView('auth/login');
}
public function logout() {
$this->authService->logout();
$this->logger->info("User logged out");
header('Location: /admin/login');
exit;
}
public function profile() {
if (!$this->authService->isAuthenticated()) {
header('Location: /admin/login');
exit;
}
$user = $this->authService->getCurrentUser();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$currentPassword = $_POST['current_password'] ?? '';
$newPassword = $_POST['new_password'] ?? '';
$result = $this->authService->updateProfile($user['id'], $email, $currentPassword, $newPassword);
if ($result['success']) {
$this->logger->info("Profile updated: {$user['username']}");
$this->jsonResponse(['success' => true, 'message' => 'Profile updated successfully']);
} else {
$this->jsonResponse(['success' => false, 'message' => $result['message']]);
}
}
$this->renderView('auth/profile', ['user' => $user]);
}
private function jsonResponse(array $data) {
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
private function renderView(string $view, array $data = []) {
extract($data);
require __DIR__ . "/../../public/templates/{$view}.php";
}
}