X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/d336ba687460d2bca898e86c12a26224fc36f071..refs/pull/5676/head:/app/Api/ApiToken.php diff --git a/app/Api/ApiToken.php b/app/Api/ApiToken.php index 838e70abb..ca89c813e 100644 --- a/app/Api/ApiToken.php +++ b/app/Api/ApiToken.php @@ -1,9 +1,63 @@ - 'date:Y-m-d', + ]; + + /** + * Get the user that this token belongs to. + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + + /** + * Get the default expiry value for an API token. + * Set to 100 years from now. + */ + public static function defaultExpiry(): string + { + return Carbon::now()->addYears(100)->format('Y-m-d'); + } + + /** + * {@inheritdoc} + */ + public function logDescriptor(): string + { + return "({$this->id}) {$this->name}; User: {$this->user->logDescriptor()}"; + } + /** + * Get the URL for managing this token. + */ + public function getUrl(string $path = ''): string + { + return url("/http/source.bookstackapp.com/api-tokens/{$this->user_id}/{$this->id}/" . trim($path, '/')); + } }