From 00e79b9b9c68439deec4b229a883d6f975208ef6 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Fri, 23 Mar 2018 08:47:18 +0800 Subject: [PATCH] Update flash message for unauthorized access --- app/Exceptions/Handler.php | 4 ++-- app/Http/Middleware/Role.php | 2 +- resources/lang/en/auth.php | 3 +++ resources/lang/id/auth.php | 3 +++ tests/Feature/ManageProjectsTest.php | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 322690b..355f49b 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -54,7 +54,7 @@ class Handler extends ExceptionHandler return response()->json(['error' => 'Forbidden Action.'], 403); } - flash()->error('Invalid access'); + flash(__('auth.unauthorized_access', ['url' => $request->path()]), 'danger'); return redirect()->home(); } @@ -64,7 +64,7 @@ class Handler extends ExceptionHandler return response()->json(['error' => 'Data not found.'], 404); } - flash()->error('Data not found.'); + flash('Data not found.', 'danger'); return redirect()->home(); } diff --git a/app/Http/Middleware/Role.php b/app/Http/Middleware/Role.php index b05b85c..f0a0d3c 100644 --- a/app/Http/Middleware/Role.php +++ b/app/Http/Middleware/Role.php @@ -29,7 +29,7 @@ class Role // Cek apakah grup user ada di dalam array $nameArray? if (auth()->user()->hasRoles($nameArray) == false) { - flash()->error('Anda tidak dapat mengakses halaman '.$request->path().'.'); + flash(__('auth.unauthorized_access', ['url' => $request->path()]), 'danger'); return redirect()->route('home'); } diff --git a/resources/lang/en/auth.php b/resources/lang/en/auth.php index bbc3777..113502b 100644 --- a/resources/lang/en/auth.php +++ b/resources/lang/en/auth.php @@ -36,4 +36,7 @@ return [ 'old_password' => 'Old Password', 'new_password' => 'New Password', 'new_password_confirmation' => 'Confirm new Password', + + // Authorization + 'unauthorized_access' => 'You cannot access :url page.', ]; diff --git a/resources/lang/id/auth.php b/resources/lang/id/auth.php index ce03c7a..ad29c3d 100644 --- a/resources/lang/id/auth.php +++ b/resources/lang/id/auth.php @@ -36,4 +36,7 @@ return [ 'old_password' => 'Password Lama', 'new_password' => 'Password Baru', 'new_password_confirmation' => 'Ulangi Password Baru', + + // Authorization + 'unauthorized_access' => 'Anda tidak dapat mengakses halaman :url.', ]; diff --git a/tests/Feature/ManageProjectsTest.php b/tests/Feature/ManageProjectsTest.php index f61e278..f5c19c2 100644 --- a/tests/Feature/ManageProjectsTest.php +++ b/tests/Feature/ManageProjectsTest.php @@ -164,7 +164,7 @@ class ManageProjectsTest extends TestCase $this->press(trans('project.create')); $this->seePageIs(route('projects.create')); - $this->see('Mohon periksa kembali form isian Anda.'); + $this->see(__('validation.flash_message')); } /** @test */