From 1855d877150b3f84d6b080ecf685b149ca428ab7 Mon Sep 17 00:00:00 2001 From: Kovah Date: Fri, 31 Jan 2020 12:25:03 +0100 Subject: [PATCH] Refactor the trash controller, add custom error views (WIP) --- app/Http/Controllers/App/TrashController.php | 8 ++-- nginx.conf | 1 + resources/docker/nginx/site.conf | 1 + resources/lang/en/trash.php | 11 +++-- resources/views/errors/401.blade.php | 5 +++ resources/views/errors/403.blade.php | 5 +++ resources/views/errors/404.blade.php | 5 +++ resources/views/errors/419.blade.php | 5 +++ resources/views/errors/429.blade.php | 5 +++ resources/views/errors/500.blade.php | 5 +++ resources/views/errors/503.blade.php | 5 +++ resources/views/layouts/errors.blade.php | 43 ++++++++++++++++++++ 12 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 resources/views/errors/401.blade.php create mode 100644 resources/views/errors/403.blade.php create mode 100644 resources/views/errors/404.blade.php create mode 100644 resources/views/errors/419.blade.php create mode 100644 resources/views/errors/429.blade.php create mode 100644 resources/views/errors/500.blade.php create mode 100644 resources/views/errors/503.blade.php create mode 100644 resources/views/layouts/errors.blade.php diff --git a/app/Http/Controllers/App/TrashController.php b/app/Http/Controllers/App/TrashController.php index 390d00bb..b9c53bc1 100644 --- a/app/Http/Controllers/App/TrashController.php +++ b/app/Http/Controllers/App/TrashController.php @@ -82,7 +82,7 @@ class TrashController extends Controller break; } - if (empty($entries)) { + if ($entries->isEmpty()) { alert(trans('trash.delete_no_entries'), 'warning'); return redirect()->back(); } @@ -124,16 +124,16 @@ class TrashController extends Controller } if (empty($entry)) { - abort(404); + abort(404, trans('trash.restore.not_found')); } if ($entry->user_id !== auth()->id()) { - abort(403); + abort(403, trans('trash.restore.not_allowed')); } $entry->restore(); - alert(trans('trash.delete_restore.' . $model), 'success'); + alert(trans('trash.restore.' . $model), 'success'); return redirect()->route('get-trash'); } diff --git a/nginx.conf b/nginx.conf index b3862cca..a6dec67d 100644 --- a/nginx.conf +++ b/nginx.conf @@ -46,6 +46,7 @@ server { # Error pages error_page 404 /index.php; + error_page 403 /index.php; # PHP handling location ~ \.php$ { diff --git a/resources/docker/nginx/site.conf b/resources/docker/nginx/site.conf index 050effd8..5fac3663 100644 --- a/resources/docker/nginx/site.conf +++ b/resources/docker/nginx/site.conf @@ -39,6 +39,7 @@ server { # Error pages error_page 404 /index.php; + error_page 403 /index.php; # PHP handling location ~ \.php$ { diff --git a/resources/lang/en/trash.php b/resources/lang/en/trash.php index ccec4824..79975c99 100644 --- a/resources/lang/en/trash.php +++ b/resources/lang/en/trash.php @@ -20,9 +20,12 @@ return [ 'delete_success.tags' => 'Permanently deleted all tags.', 'delete_success.notes' => 'Permanently deleted all notes.', - 'delete_restore.link' => 'Restored the link from trash.', - 'delete_restore.list' => 'Restored the list from trash.', - 'delete_restore.tag' => 'Restored the tag from trash.', - 'delete_restore.note' => 'Restored the note from trash.', + 'restore.link' => 'Restored the link from trash.', + 'restore.list' => 'Restored the list from trash.', + 'restore.tag' => 'Restored the tag from trash.', + 'restore.note' => 'Restored the note from trash.', + + 'restore.not_found' => 'The item to be restored could not be found.', + 'restore.not_allowed' => 'You are not allowed to restore this item.', ]; diff --git a/resources/views/errors/401.blade.php b/resources/views/errors/401.blade.php new file mode 100644 index 00000000..042bee99 --- /dev/null +++ b/resources/views/errors/401.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.errors') + +@section('title', __('Unauthorized')) +@section('code', '401') +@section('message', __($exception->getMessage() ?: 'Unauthorized')) diff --git a/resources/views/errors/403.blade.php b/resources/views/errors/403.blade.php new file mode 100644 index 00000000..33a4f856 --- /dev/null +++ b/resources/views/errors/403.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.errors') + +@section('title', __('Forbidden')) +@section('code', '403') +@section('message', __($exception->getMessage() ?: 'Forbidden')) diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php new file mode 100644 index 00000000..bc98884d --- /dev/null +++ b/resources/views/errors/404.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.errors') + +@section('title', __('Not Found')) +@section('code', '404') +@section('message', __($exception->getMessage() ?: 'Page not Found')) diff --git a/resources/views/errors/419.blade.php b/resources/views/errors/419.blade.php new file mode 100644 index 00000000..2c20974a --- /dev/null +++ b/resources/views/errors/419.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.errors') + +@section('title', __('Page Expired')) +@section('code', '419') +@section('message', __($exception->getMessage() ?: 'Page Expired')) diff --git a/resources/views/errors/429.blade.php b/resources/views/errors/429.blade.php new file mode 100644 index 00000000..8dbec91f --- /dev/null +++ b/resources/views/errors/429.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.errors') + +@section('title', __('Too Many Requests')) +@section('code', '429') +@section('message', __($exception->getMessage() ?: 'Too Many Requests')) diff --git a/resources/views/errors/500.blade.php b/resources/views/errors/500.blade.php new file mode 100644 index 00000000..873470e4 --- /dev/null +++ b/resources/views/errors/500.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.errors') + +@section('title', __('Server Error')) +@section('code', '500') +@section('message', __($exception->getMessage() ?: 'Server Error')) diff --git a/resources/views/errors/503.blade.php b/resources/views/errors/503.blade.php new file mode 100644 index 00000000..6b64d761 --- /dev/null +++ b/resources/views/errors/503.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.errors') + +@section('title', __('Service Unavailable')) +@section('code', '503') +@section('message', __($exception->getMessage() ?: 'Service Unavailable')) diff --git a/resources/views/layouts/errors.blade.php b/resources/views/layouts/errors.blade.php new file mode 100644 index 00000000..aae21390 --- /dev/null +++ b/resources/views/layouts/errors.blade.php @@ -0,0 +1,43 @@ + + + + + + + + {{ config('app.name', 'LinkAce') }} + + + + @include('partials.favicon') + + +
+ +
+
+ @lang('linkace.linkace') +
+ +
+
+ @yield('code') - @yield('title') +
+
+ @yield('message') +
+
+ + Go back +
+ + + + + @stack('scripts') + +
+
+ +