From 66bdcf04f431d615b5fac93e7677e7304888e90c Mon Sep 17 00:00:00 2001 From: winter Date: Sat, 18 Jan 2025 20:02:39 +0000 Subject: implement settings editor page --- Digitigrade/GlobalSettings.php | 13 +++++++++++++ Digitigrade/Model/UserAccount.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) (limited to 'Digitigrade') diff --git a/Digitigrade/GlobalSettings.php b/Digitigrade/GlobalSettings.php index 435c85a..52c6582 100644 --- a/Digitigrade/GlobalSettings.php +++ b/Digitigrade/GlobalSettings.php @@ -25,6 +25,19 @@ class GlobalSettings extends Singleton { return $stmt->fetchColumn(0) ?: null; } + /** + * Gets a boolean setting's value. + * @param string $key which setting to get + * @return ?bool the value, or null if not set + */ + public function getBool(string $key): ?bool { + return match ($this->get($key)) { + '', 'false' => false, + '1', 'true' => true, + default => null + }; + } + /** * Sets the value of a setting. * @param string $key which setting to modify diff --git a/Digitigrade/Model/UserAccount.php b/Digitigrade/Model/UserAccount.php index d0fa94b..37e0c7e 100644 --- a/Digitigrade/Model/UserAccount.php +++ b/Digitigrade/Model/UserAccount.php @@ -1,6 +1,7 @@ passwordHash); } + + /** + * Throws if this user isn't an admin. + * @return self this user (so you can use it in chains) + */ + public function requireAdmin(): self { + if (!$this->isAdmin) { + throw new Forbidden(); + } + return $this; + } } \ No newline at end of file -- cgit v1.3