diff options
| author | winter | 2025-01-01 19:52:18 +0000 |
|---|---|---|
| committer | winter | 2025-01-01 19:52:18 +0000 |
| commit | fea439b57f9ba225e2d3169d7615c0bd2aecabe4 (patch) | |
| tree | 477357cb50c029fde839aea272ba30b20a66129f /Digitigrade | |
| parent | 02a6acd4cfddaecd9075b706fdbdc0396d76d8c3 (diff) | |
ultra basic post form
doesn't do much but i just wanted to get this working at a bare minimum
Diffstat (limited to 'Digitigrade')
| -rw-r--r-- | Digitigrade/Model/UserAccount.php | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Digitigrade/Model/UserAccount.php b/Digitigrade/Model/UserAccount.php index 3d0e2a4..72a9ce9 100644 --- a/Digitigrade/Model/UserAccount.php +++ b/Digitigrade/Model/UserAccount.php @@ -1,6 +1,7 @@ <?php namespace Digitigrade\Model; +use Digitigrade\HttpResponseStatus\Unauthorized; use Digitigrade\Model; class UserAccount extends Model { @@ -46,6 +47,18 @@ class UserAccount extends Model { return Session::findByToken($token)?->userAccount; } + /** + * Gets the currently logged-in user account, or throws an error + * @throws Unauthorized if no account could be found + */ + public static function requireByCurrentSession(): self { + $user = self::findByCurrentSession(); + if ($user == null) { + throw new Unauthorized(); + } + return $user; + } + public function verifyPassword(#[\SensitiveParameter] $attemptedPassword): bool { return password_verify($attemptedPassword, $this->passwordHash); } |
