Migrate many view templates from raw PHP to Twig and modernize UI/UX for 2FA and settings. Controllers updated to provide avatar data and two-factor info (ProfileController, UserController) and SettingsController now includes timezone lists, notification preset selection, cron path, cached update state and rollback availability. ErrorHandler now attempts to render error pages via a new Core\TwigService with a safe fallback to raw PHP views. TwoFactorService generation silences deprecated warnings during QR code creation. Numerous .php view files were removed and replaced with .twig equivalents (2fa setup/verify/backup-codes and many auth, dashboard, domains, errors, layout, users, tags, tld-registry, etc.), and core/TwigService was added. These changes move the app toward a Twig-based templating system, improve 2FA flows, surface avatar images in lists/profiles, and make error rendering more robust.
64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Core;
|
|
|
|
abstract class Controller
|
|
{
|
|
protected function view(string $view, array $data = []): void
|
|
{
|
|
$twigPath = __DIR__ . "/../app/Views/$view.twig";
|
|
|
|
if (file_exists($twigPath)) {
|
|
$twig = TwigService::getInstance();
|
|
echo $twig->render("$view.twig", $data);
|
|
return;
|
|
}
|
|
|
|
// Fallback to legacy PHP view during migration
|
|
extract($data);
|
|
$viewPath = __DIR__ . "/../app/Views/$view.php";
|
|
|
|
if (!file_exists($viewPath)) {
|
|
throw new \Exception("View not found: $view");
|
|
}
|
|
|
|
require $viewPath;
|
|
}
|
|
|
|
protected function json($data, int $status = 200): void
|
|
{
|
|
http_response_code($status);
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data);
|
|
exit;
|
|
}
|
|
|
|
protected function redirect(string $path): void
|
|
{
|
|
header("Location: $path");
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Verify CSRF token and redirect with error if invalid
|
|
*
|
|
* @param string $redirectUrl URL to redirect to on failure
|
|
* @return bool True if valid, redirects on failure
|
|
*/
|
|
protected function verifyCsrf(string $redirectUrl = '/'): bool
|
|
{
|
|
return Csrf::verifyOrFail($redirectUrl);
|
|
}
|
|
|
|
/**
|
|
* Get CSRF token for forms
|
|
*
|
|
* @return string The CSRF token
|
|
*/
|
|
protected function getCsrfToken(): string
|
|
{
|
|
return Csrf::getToken();
|
|
}
|
|
}
|
|
|