X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/2a2cc858f0f95c606f2ad2542f915d3bd761775f..refs/pull/2023/head:/app/Http/Controllers/Controller.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index e34cb7e59..2e8e8ed2e 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,7 +2,6 @@ namespace BookStack\Http\Controllers; -use BookStack\Auth\User; use BookStack\Ownable; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; @@ -15,22 +14,19 @@ abstract class Controller extends BaseController use DispatchesJobs, ValidatesRequests; /** - * @var User static - */ - protected $currentUser; - - /** - * @var bool + * Controller constructor. */ - protected $signedIn; + public function __construct() + { + // + } /** - * Controller constructor. + * Check if the current user is signed in. */ - public function __construct() + protected function isSignedIn(): bool { - $this->currentUser = user(); - $this->signedIn = auth()->check(); + return auth()->check(); } /** @@ -63,7 +59,7 @@ abstract class Controller extends BaseController $response = response()->json(['error' => trans('errors.permissionJson')], 403); } else { $response = redirect('/'); - $this->showErrorNotification( trans('errors.permission')); + $this->showErrorNotification(trans('errors.permission')); } throw new HttpResponseException($response); @@ -121,7 +117,7 @@ abstract class Controller extends BaseController protected function checkPermissionOrCurrentUser(string $permissionName, int $userId) { return $this->checkPermissionOr($permissionName, function () use ($userId) { - return $userId === $this->currentUser->id; + return $userId === user()->id; }); } @@ -133,7 +129,7 @@ abstract class Controller extends BaseController */ protected function jsonError($messageText = "", $statusCode = 500) { - return response()->json(['message' => $messageText], $statusCode); + return response()->json(['message' => $messageText, 'status' => 'error'], $statusCode); } /** @@ -193,4 +189,12 @@ abstract class Controller extends BaseController { session()->flash('error', $message); } + + /** + * Get the validation rules for image files. + */ + protected function getImageValidationRules(): string + { + return 'image_extension|no_double_extension|mimes:jpeg,png,gif,webp'; + } }