Handle the ajax case of unauthenticated

parent 5d84e8f6
...@@ -5,6 +5,7 @@ namespace Modules\Core\Http\Middleware; ...@@ -5,6 +5,7 @@ namespace Modules\Core\Http\Middleware;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Routing\Redirector; use Illuminate\Routing\Redirector;
use Illuminate\Http\Response;
use Illuminate\Session\Store; use Illuminate\Session\Store;
use Modules\User\Contracts\Authentication; use Modules\User\Contracts\Authentication;
...@@ -51,6 +52,9 @@ class AdminMiddleware ...@@ -51,6 +52,9 @@ class AdminMiddleware
{ {
// Check if the user is logged in // Check if the user is logged in
if (!$this->auth->check()) { if (!$this->auth->check()) {
if ($request->ajax()) {
return response('Unauthenticated.', Response::HTTP_UNAUTHORIZED);
}
// Store the current uri in the session // Store the current uri in the session
$this->session->put('url.intended', $this->request->url()); $this->session->put('url.intended', $this->request->url());
...@@ -61,7 +65,7 @@ class AdminMiddleware ...@@ -61,7 +65,7 @@ class AdminMiddleware
// Check if the user has access to the dashboard page // Check if the user has access to the dashboard page
if (! $this->auth->hasAccess('dashboard.index')) { if (! $this->auth->hasAccess('dashboard.index')) {
// Show the insufficient permissions page // Show the insufficient permissions page
return $this->application->abort(403); return $this->application->abort(Response::HTTP_FORBIDDEN);
} }
return $next($request); return $next($request);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment