role_id); } /** * @param string|null $password * @return bool * @throws Exception */ public function validatePassword(?string $password): bool { return password_verify($password, $this->password); } /** * @return void * @throws Exception */ public function refreshCsrfToken(): void { $this->csrf_token = bin2hex(random_bytes(16)); $this->commit(); } /** * @return void * @throws Exception */ public function insertCsrfToken(): void { if(!$this->csrf_token) { $this->refreshCsrfToken(); } ?> raw("csrf_token") === $this->csrf_token; } public function requireValidCsrfToken(): void { if(!$this->validateCsrfToken()) { throw new RuntimeException(__("CSRF validation failed.")); } } public function getDateTimeCreated(): CarbonImmutable { return CarbonImmutable::parse($this->dts_created, "UTC"); } /** * @return bool * @throws Exception */ public function touch(): bool { $this->dts_last_seen = Database::dts(); return $this->commit(); } public function isAdmin(): bool { return (bool) $this->admin; } public function getUrl(): string { return sprintf("/users/%d", $this->id); } public function requireAdmin(): void { if(!$this->isAdmin()) { throw new RuntimeException(__("You do not have permission to access this page.")); } } }