initial import
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/*
|
||||
* login.php
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/auth.php';
|
||||
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
ini_set('log_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$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'] ?? '';
|
||||
$preferences = array();
|
||||
|
||||
foreach (explode(',', $header) as $part) {
|
||||
$pieces = array_map('trim', explode(';', $part));
|
||||
$lang = strtolower($pieces[0] ?? '');
|
||||
$quality = 1.0;
|
||||
|
||||
foreach (array_slice($pieces, 1) as $piece) {
|
||||
if (strpos($piece, 'q=') === 0) {
|
||||
$quality = (float)substr($piece, 2);
|
||||
}
|
||||
}
|
||||
|
||||
if ($lang !== '') {
|
||||
$preferences[] = array('lang' => $lang, 'quality' => $quality);
|
||||
}
|
||||
}
|
||||
|
||||
usort($preferences, function ($a, $b) {
|
||||
return $a['quality'] < $b['quality'] ? 1 : -1;
|
||||
});
|
||||
|
||||
foreach ($preferences as $preference) {
|
||||
$lang = $preference['lang'];
|
||||
$primary = explode('-', $lang, 2)[0];
|
||||
|
||||
if (isset($supported[$lang])) {
|
||||
return $lang;
|
||||
}
|
||||
|
||||
if (isset($supported[$primary])) {
|
||||
return $primary;
|
||||
}
|
||||
}
|
||||
|
||||
return $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',
|
||||
),
|
||||
);
|
||||
$language = detect_login_language($texts, 'en');
|
||||
$styleVersion = @filemtime(__DIR__ . '/styles.css') ?: time();
|
||||
|
||||
if ($auth->currentUser() !== null && $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
try {
|
||||
$auth->login($_POST['email'] ?? '', $_POST['password'] ?? '');
|
||||
header('Location: /');
|
||||
exit;
|
||||
} catch (Throwable $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
|
||||
<?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>
|
||||
Reference in New Issue
Block a user