aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model
diff options
context:
space:
mode:
authorwinter2025-01-18 20:02:39 +0000
committerwinter2025-01-18 20:02:39 +0000
commit66bdcf04f431d615b5fac93e7677e7304888e90c (patch)
treed75f1b299e8ed2ff8d2fd6ccd42185cfb06b6729 /Digitigrade/Model
parent00ab9734e880219fa68fed98cefda5ce12958e4b (diff)
implement settings editor page
Diffstat (limited to 'Digitigrade/Model')
-rw-r--r--Digitigrade/Model/UserAccount.php13
1 files changed, 13 insertions, 0 deletions
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 @@
<?php
namespace Digitigrade\Model;
+use Digitigrade\HttpResponseStatus\Forbidden;
use Digitigrade\HttpResponseStatus\Unauthorized;
use Digitigrade\Model;
@@ -10,6 +11,7 @@ class UserAccount extends Model {
public string $passwordHash;
public ?Actor $actor;
public bool $banned = false;
+ public bool $isAdmin = false;
public static function create(string $email, #[\SensitiveParameter] string $password): self {
$user = new self();
@@ -66,4 +68,15 @@ class UserAccount extends Model {
public function verifyPassword(#[\SensitiveParameter] $attemptedPassword): bool {
return password_verify($attemptedPassword, $this->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