Add Auth0, partial support

This commit is contained in:
2024-06-21 19:01:12 -04:00
parent 41853a7645
commit 4aa6e832c7
18 changed files with 2756 additions and 55 deletions

View File

@@ -1,55 +1,53 @@
<?php declare(strict_types=1);
const MPJ_VERSION = '4.0.0';
use Dotenv\Dotenv;
use MyPrayerJournal\{Auth, Layout};
function html_head(string $title): void
{ ?>
<!DOCTYPE html>
<head lang=en>
<meta name=viewport content="width=device-width, initial-scale=1">
<meta name=description content="Online prayer journal - free w/Google or Microsoft account">
<title><?=$title?> &#xab; myPrayerJournal</title>
<link href=https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css rel=stylesheet
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin=anonymous>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel=stylesheet>
<link href=/style/style.css rel=stylesheet>
</head><?php
require __DIR__ . '/vendor/autoload.php';
/** The version of this application */
const MPJ_VERSION = '4.0.0-alpha1';
(Dotenv::createImmutable(__DIR__))->load();
session_start();
$auth0_session = Auth::client()->getCredentials();
if (!is_null($auth0_session)) {
$_SESSION['user_id'] = $auth0_session->user['sub'];
}
/**
* Is this an htmx request?
*
* @return bool True if this is an htmx request, false if not
*/
function is_htmx(): bool
{
return key_exists('HTTP_HX_REQUEST', $_SERVER) && !key_exists('HTTP_HX_HISTORY_RESTORE_REQUEST', $_SERVER);
}
function page_link(string $href, string $text, array $attrs = []): void
{ ?>
<a href="<?=$href?>" hx-get="<?=$href?>" hx-target="#top" hx-swap=innerHTML hx-push-url=true<?php
foreach ($attrs as $key => $value) echo " $key=\"" . htmlspecialchars($value) . "\""; ?>><?=$text?></a><?php
{
echo '<a href="' . $href . '" hx-get="' . $href . '" hx-target="#top" hx-swap=innerHTML hx-push-url=true';
foreach ($attrs as $key => $value) echo " $key=\"" . htmlspecialchars($value) . "\"";
echo ">$text</a>";
}
function html_foot(): void
function page_head(string $title): void
{
$version = MPJ_VERSION;
while (!str_ends_with($version, '.0')) $version = substr($version, 0, strlen($version) - 2); ?>
<footer class=container-fluid>
<p class="text-muted text-end">
myPrayerJournal <?=$version?><br>
<em>
<small><?php
page_link('/legal/privacy-policy', 'Privacy Policy');
echo ' &bull; ';
page_link('/legal/terms-of-service', 'Terms of Service');
echo ' &bull; '; ?>
<a href=https://git.bitbadger.solutions/bit-badger/myPrayerJournal target=_blank
rel=noopener>Developed</a> and hosted by
<a href=https://bitbadger.solutions target=_blank rel=noopener>Bit Badger Solutions</a>
</small>
</em>
Htmx.Script.minified
<script>if (!htmx) document.write('<script src=\"/script/htmx.min.js\"><\/script>')</script>
<script async src=https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin=anonymous></script>
<script>
setTimeout(function () {
if (!bootstrap) document.write('<script src=\"/script/bootstrap.bundle.min.js\"><\/script>')
}, 2000)
</script>
<script src=/script/mpj.js></script>
</footer><?php
}
Layout::htmlHead($title);
echo '<body>';
if (!is_htmx()) echo '<section id=top aria-label="Top navigation">';
Layout::navBar();
echo '<main role=main>';
}
function page_foot(): void
{
echo '</main>';
if (!is_htmx()) {
echo '</section>';
Layout::htmlFoot();
}
echo '</body></html>';
}