X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8b550991a4dbcd7a05e08e8f600b5444d5f4004d..refs/pull/2272/head:/app/Http/Controllers/Controller.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 034c852de..6a1dfcb01 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -8,6 +8,7 @@ use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; +use Illuminate\Validation\ValidationException; abstract class Controller extends BaseController { @@ -59,7 +60,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); @@ -129,24 +130,7 @@ abstract class Controller extends BaseController */ protected function jsonError($messageText = "", $statusCode = 500) { - return response()->json(['message' => $messageText], $statusCode); - } - - /** - * Create the response for when a request fails validation. - * @param \Illuminate\Http\Request $request - * @param array $errors - * @return \Symfony\Component\HttpFoundation\Response - */ - protected function buildFailedValidationResponse(Request $request, array $errors) - { - if ($request->expectsJson()) { - return response()->json(['validation' => $errors], 422); - } - - return redirect()->to($this->getRedirectUrl()) - ->withInput($request->input()) - ->withErrors($errors, $this->errorBag()); + return response()->json(['message' => $messageText, 'status' => 'error'], $statusCode); } /** @@ -189,4 +173,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'; + } }