Move rendering into private templates
Add an explicit template renderer with HTML views and partials for the app, bootstrap, package, and catalog pages. Move shared reporting setup into config/reporting.php and relocate stylesheet assets under css/.
This commit is contained in:
@@ -4,21 +4,14 @@
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/private/auth.php';
|
||||
require_once __DIR__ . '/private/Template.php';
|
||||
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
ini_set('log_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
require_once __DIR__ . '/config/reporting.php';
|
||||
|
||||
$auth = new RacketSandboxAuth(__DIR__ . '/data/racket-sandbox.sqlite');
|
||||
|
||||
$error = '';
|
||||
|
||||
function h($s)
|
||||
{
|
||||
return htmlspecialchars((string)$s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
}
|
||||
|
||||
function detect_login_language($supported, $fallback)
|
||||
{
|
||||
$header = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '';
|
||||
@@ -61,26 +54,10 @@ function detect_login_language($supported, $fallback)
|
||||
}
|
||||
|
||||
$pageTitle = 'Racket ChatGPT Agent Sandbox Creator';
|
||||
$texts = array(
|
||||
'en' => array(
|
||||
'email' => 'Email address',
|
||||
'password' => 'Password',
|
||||
'login' => 'Login',
|
||||
'account_title' => 'Want to try it?',
|
||||
'account_text' => 'If you would like an account to try the sandbox, please request one from Hans Dijkema through the Racket Discourse pages.',
|
||||
'account_link' => 'Go to Racket Discourse',
|
||||
),
|
||||
'nl' => array(
|
||||
'email' => 'E-mailadres',
|
||||
'password' => 'Wachtwoord',
|
||||
'login' => 'Inloggen',
|
||||
'account_title' => 'Wil je het eens proberen?',
|
||||
'account_text' => 'Als je een account wilt om de sandbox eens uit te proberen, doe dan een verzoek aan Hans Dijkema via de Racket Discourse-pagina\'s.',
|
||||
'account_link' => 'Naar Racket Discourse',
|
||||
),
|
||||
);
|
||||
$templateData = RacketSandboxTemplate::dataFile('login.html');
|
||||
$texts = $templateData['translations'] ?? array();
|
||||
$language = detect_login_language($texts, 'en');
|
||||
$styleVersion = @filemtime(__DIR__ . '/styles.css') ?: time();
|
||||
$styleVersion = @filemtime(__DIR__ . '/css/styles.css') ?: time();
|
||||
|
||||
if ($auth->currentUser() !== null && $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: /');
|
||||
@@ -98,46 +75,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="<?= h($language) ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><?= h($pageTitle) ?></title>
|
||||
<link rel="stylesheet" href="/styles.css?v=<?= h($styleVersion) ?>">
|
||||
</head>
|
||||
<body class="simple-doc login-page">
|
||||
|
||||
<main class="login-layout">
|
||||
<section class="login-panel">
|
||||
<h1><?= h($pageTitle) ?></h1>
|
||||
$loginText = $texts[$language];
|
||||
$errorHtml = $error === ''
|
||||
? ''
|
||||
: RacketSandboxTemplate::renderFile('partials/message.html', array(
|
||||
'class' => 'error',
|
||||
'message' => $error,
|
||||
));
|
||||
|
||||
<?php if ($error !== ''): ?>
|
||||
<div class="error"><?= h($error) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="/login.php">
|
||||
|
||||
<label>
|
||||
<?= h($texts[$language]['email']) ?><br>
|
||||
<input type="email" name="email" autocomplete="username" required>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<?= h($texts[$language]['password']) ?><br>
|
||||
<input type="password" name="password" autocomplete="current-password" required>
|
||||
</label>
|
||||
|
||||
<button type="submit"><?= h($texts[$language]['login']) ?></button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<aside class="login-request-panel">
|
||||
<h2><?= h($texts[$language]['account_title']) ?></h2>
|
||||
<p><?= h($texts[$language]['account_text']) ?></p>
|
||||
<p><a href="https://racket.discourse.group/"><?= h($texts[$language]['account_link']) ?></a></p>
|
||||
</aside>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
echo RacketSandboxTemplate::renderFile('login.html', array(
|
||||
'language' => $language,
|
||||
'page_title' => $pageTitle,
|
||||
'style_version' => $styleVersion,
|
||||
'error_html' => $errorHtml,
|
||||
'email_label' => $loginText['email'],
|
||||
'password_label' => $loginText['password'],
|
||||
'login_label' => $loginText['login'],
|
||||
'account_title' => $loginText['account_title'],
|
||||
'account_text' => $loginText['account_text'],
|
||||
'account_link' => $loginText['account_link'],
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user