From 12c1940897084a9ae47146d5beb29d5fac4009c9 Mon Sep 17 00:00:00 2001 From: mitchell stanley Date: Thu, 3 Mar 2016 19:42:20 +0000 Subject: [PATCH] Unauthorized url redirect configuration option --- CHANGELOG.md | 5 +++++ README.md | 4 ++++ config/entrust-gui.php | 1 + src/Http/Middleware/AdminAuth.php | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33f8d9b..1c8e87a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Add user name field to users form + +## [0.6.0] - 2016-03-03 +### Changed +- Config option for changing unauthorized redirects + ## [0.5.0] - 2015-09-13 ### Changed - Console command for generating model files diff --git a/README.md b/README.md index 591e633..e52122b 100644 --- a/README.md +++ b/README.md @@ -462,6 +462,10 @@ class Permission extends EntrustPermission implements ValidatingModelInterface ``` ## Upgrade Guide / Breaking Changes +### 0.6 + +Includes a new config key, "unauthorized-url" which lets you set the redirection if a user is not authorized. If this key is not found, it will use the old url, /auth/login. The default is set to /auth/login to match Laravel 5.1's documentation on the [authentication routes](https://www.laravel.com/docs/5.1/authentication#included-routing). + ### 0.3.* to 0.4.0 Starting from 0.4.0 Entrust GUI switches from ```dwightwatson/validating``` to ```esensi/model```. diff --git a/config/entrust-gui.php b/config/entrust-gui.php index 339b4b9..98cd3cd 100644 --- a/config/entrust-gui.php +++ b/config/entrust-gui.php @@ -8,6 +8,7 @@ "permissions" => 5, ], "middleware" => 'entrust-gui.admin', + "unauthorized-url" => '/login', "middleware-role" => 'admin', "confirmable" => false, ]; diff --git a/src/Http/Middleware/AdminAuth.php b/src/Http/Middleware/AdminAuth.php index e1a3829..c1a25af 100644 --- a/src/Http/Middleware/AdminAuth.php +++ b/src/Http/Middleware/AdminAuth.php @@ -52,7 +52,7 @@ public function handle($request, Closure $next) if ($request->ajax()) { return $this->response->make('Unauthorized.', 401); } else { - return $this->redirect->guest('auth/login'); + return $this->redirect->guest($this->config->get('entrust-gui.unauthorized-url', 'auth/login')); } } elseif (! $request->user()->hasRole($this->config->get('entrust-gui.middleware-role'))) { return $this->response->make('Unauthorized.', 401); //Or redirect() or whatever you want