Started putting default templates together

This commit is contained in:
Barnaby Walters 2021-06-06 17:47:06 +02:00
parent 825ec1c0e5
commit 7442da1ae9
4 changed files with 43 additions and 2 deletions

View File

@ -60,7 +60,9 @@ class Server {
'logger' => null,
'callbacks' => [
self::CUSTOMIZE_AUTHORIZATION_CODE => function (array $code) { return $code; }, // Default to no-op.
self::SHOW_AUTHORIZATION_PAGE => function (ServerRequestInterface $request, array $authenticationResult, string $authenticationRedirect) { }, // TODO: Put the default implementation here.
self::SHOW_AUTHORIZATION_PAGE => function (ServerRequestInterface $request, array $authenticationResult, string $authenticationRedirect, ?array $clientHApp) {
// TODO: Put the default implementation here.
},
self::HANDLE_NON_INDIEAUTH_REQUEST => function (ServerRequestInterface $request) { return null; }, // Default to no-op.
],
'authorizationCodeStorage' => null,

View File

@ -77,3 +77,17 @@ function trySetLogger($target, LoggerInterface $logger) {
}
return $target;
}
function renderTemplate(string $template, array $context=[]) {
$render = function ($__template, $__templateData) {
$render = function ($template, $data){
return renderTemplate($template, $data);
};
ob_start();
extract($__templateData);
unset($__templateData);
include $__template;
return ob_get_clean();
};
return $render($template, $context);
}

View File

@ -0,0 +1,24 @@
<?php
/** @var string $authenticationRedirect The URL to POST to to authorize the app, or to set as the redirect URL for a logout action if the user wants to continue as a different user. */
/** @var Psr\Http\Message\ServerRequestInterface $request */
/** @var array|null $clientHApp */
/** @var array $me */
/** @var string $csrfFormElement A pre-rendered CSRF form element which must be output inside the authorization form. */
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>IndieAuth Authorize</title>
</head>
<body>
<form method="post" action="<?= $authenticationRedirect ?>">
<?= $csrfFormElement ?>
<h1>Authorize</h1>
<!-- TODO -->
</form>
</body>
</html>

View File

@ -10,6 +10,7 @@ const TMP_DIR = __DIR__ . '/tmp';
class FilesystemJsonStorageTest extends TestCase {
protected function setUp(): void {
@mkdir(TMP_DIR);
// Clean tmp dir.
foreach (new DirectoryIterator(TMP_DIR) as $fileInfo) {
if ($fileInfo->isFile()) {
@ -31,7 +32,7 @@ class FilesystemJsonStorageTest extends TestCase {
$s = new FilesystemJsonStorage(TMP_DIR, 0, false);
$t1data = ['example' => 'data'];
$t1path = TMP_DIR . '/t1.json';
$t1path = $s->getPath('t1');
$this->assertTrue($s->put('t1', $t1data), "Saving t1 data failed");