You have been banned {% if globals.active_ban_info.permanent %}permanently{% else %}for {{ globals.active_ban_info.remainingString }}{% endif %} since .
@@ -47,20 +48,19 @@ {% endif %}diff --git a/src/CSRF.php b/src/CSRF.php index ffaab08c..96f542fb 100644 --- a/src/CSRF.php +++ b/src/CSRF.php @@ -4,9 +4,13 @@ namespace Misuzu; use Index\CsrfToken; final class CSRF { - private static CsrfToken $instance; + private static ?CsrfToken $instance = null; private static string $secretKey = ''; + public static function available(): bool { + return self::$instance !== null; + } + public static function create(string $identity, ?string $secretKey = null): CsrfToken { if($secretKey === null) $secretKey = self::$secretKey; @@ -21,14 +25,17 @@ final class CSRF { } public static function validate(string $token, int $tolerance = -1): bool { - return self::$instance->verifyToken($token, $tolerance); + return self::$instance?->verifyToken($token, $tolerance) ?? false; } public static function token(): string { - return self::$instance->createToken(); + return self::$instance?->createToken() ?? ''; } public static function validateRequest(int $tolerance = -1): bool { + if(self::$instance === null) + return false; + $token = (string)filter_input(INPUT_POST, '_csrf'); if(empty($token)) $token = (string)filter_input(INPUT_GET, 'csrf'); diff --git a/src/TemplatingExtension.php b/src/TemplatingExtension.php index 793f3e36..0545ca64 100644 --- a/src/TemplatingExtension.php +++ b/src/TemplatingExtension.php @@ -31,6 +31,7 @@ final class TemplatingExtension extends AbstractExtension { return [ new TwigFunction('asset', $this->getAssetPath(...)), new TwigFunction('url', $this->ctx->urls->format(...)), + new TwigFunction('csrf_available', CSRF::available(...)), new TwigFunction('csrf_token', CSRF::token(...)), new TwigFunction('git_commit_hash', GitInfo::hash(...)), new TwigFunction('git_tag', GitInfo::tag(...)), diff --git a/templates/html.twig b/templates/html.twig new file mode 100644 index 00000000..e1c7c899 --- /dev/null +++ b/templates/html.twig @@ -0,0 +1,13 @@ + + +
+ + {% if html_title is defined and html_title is not empty %}You have been banned {% if globals.active_ban_info.permanent %}permanently{% else %}for {{ globals.active_ban_info.remainingString }}{% endif %} since .
@@ -47,20 +48,19 @@ {% endif %}