Commit d2937ea7 authored by Taylor Otwell's avatar Taylor Otwell

Working on stack.

parent 2893433b
<?php namespace App\Http\Filters; <?php namespace App\Http\Middleware;
use Illuminate\Http\Request; use Closure;
use Illuminate\Routing\Route; use Illuminate\Routing\Route;
use Illuminate\Contracts\Auth\Authenticator; use Illuminate\Contracts\Auth\Authenticator;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Contracts\Routing\ResponseFactory;
class AuthFilter { class AuthMiddleware implements Middleware {
/** /**
* The authenticator implementation. * The authenticator implementation.
...@@ -36,13 +37,13 @@ class AuthFilter { ...@@ -36,13 +37,13 @@ class AuthFilter {
} }
/** /**
* Run the request filter. * Handle an incoming request.
* *
* @param \Illuminate\Routing\Route $route * @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Http\Request $request * @param \Closure $next
* @return mixed * @return \Symfony\Component\HttpFoundation\Response
*/ */
public function filter(Route $route, Request $request) public function handle($request, Closure $next)
{ {
if ($this->auth->guest()) if ($this->auth->guest())
{ {
...@@ -55,6 +56,8 @@ class AuthFilter { ...@@ -55,6 +56,8 @@ class AuthFilter {
return $this->response->redirectGuest('auth/login'); return $this->response->redirectGuest('auth/login');
} }
} }
return $next($request);
} }
} }
<?php namespace App\Http\Filters; <?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Contracts\Auth\Authenticator; use Illuminate\Contracts\Auth\Authenticator;
class BasicAuthFilter { class BasicAuthMiddleware implements Middleware {
/** /**
* The authenticator implementation. * The authenticator implementation.
...@@ -23,13 +25,15 @@ class BasicAuthFilter { ...@@ -23,13 +25,15 @@ class BasicAuthFilter {
} }
/** /**
* Run the request filter. * Handle an incoming request.
* *
* @return mixed * @param \Symfony\Component\HttpFoundation\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
*/ */
public function filter() public function handle($request, Closure $next)
{ {
return $this->auth->basic(); return $this->auth->basic() ?: $next($request);
} }
} }
<?php namespace App\Http\Filters; <?php namespace App\Http\Middleware;
use Illuminate\Http\Request; use Closure;
use Illuminate\Routing\Route; use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Session\TokenMismatchException; use Illuminate\Session\TokenMismatchException;
class CsrfFilter { class CsrfMiddleware implements Middleware {
/** /**
* Run the request filter. * Handle an incoming request.
* *
* @param \Illuminate\Routing\Route $route * @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Http\Request $request * @param \Closure $next
* @return void * @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Session\TokenMismatchException
*/ */
public function filter(Route $route, Request $request) public function handle($request, Closure $next)
{ {
if ($request->getSession()->token() != $request->input('_token')) if ($request->getSession()->token() != $request->input('_token'))
{ {
throw new TokenMismatchException; throw new TokenMismatchException;
} }
return $next($request);
} }
} }
<?php namespace App\Http\Filters; <?php namespace App\Http\Middleware;
use Illuminate\Contracts\Auth\Authenticator; use Closure;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Contracts\Auth\Authenticator;
use Illuminate\Contracts\Routing\Middleware;
class GuestFilter { class GuestMiddleware implements Middleware {
/** /**
* The authenticator implementation. * The authenticator implementation.
...@@ -24,16 +26,20 @@ class GuestFilter { ...@@ -24,16 +26,20 @@ class GuestFilter {
} }
/** /**
* Run the request filter. * Handle an incoming request.
* *
* @return mixed * @param \Symfony\Component\HttpFoundation\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
*/ */
public function filter() public function handle($request, Closure $next)
{ {
if ($this->auth->check()) if ($this->auth->check())
{ {
return new RedirectResponse(url('/')); return new RedirectResponse(url('/'));
} }
return $next($request);
} }
} }
<?php namespace App\Http\Filters; <?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Foundation\Application;
class MaintenanceFilter { class MaintenanceMiddleware {
/** /**
* The application implementation. * The application implementation.
...@@ -24,16 +26,20 @@ class MaintenanceFilter { ...@@ -24,16 +26,20 @@ class MaintenanceFilter {
} }
/** /**
* Run the request filter. * Handle an incoming request.
* *
* @return mixed * @param \Symfony\Component\HttpFoundation\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
*/ */
public function filter() public function handle($request, Closure $next)
{ {
if ($this->app->isDownForMaintenance()) if ($this->app->isDownForMaintenance())
{ {
return new Response('Be right back!', 503); return new Response('Be right back!', 503);
} }
return $next($request);
} }
} }
...@@ -6,6 +6,31 @@ use Illuminate\Routing\Stack\Builder as Stack; ...@@ -6,6 +6,31 @@ use Illuminate\Routing\Stack\Builder as Stack;
class AppServiceProvider extends ServiceProvider { class AppServiceProvider extends ServiceProvider {
/**
* All of the application's route middleware keys.
*
* @var array
*/
protected $middleware = [
'auth' => 'App\Http\Middleware\AuthMiddleware',
'auth.basic' => 'App\Http\Middleware\BasicAuthMiddleware',
'csrf' => 'App\Http\Middleware\CsrfMiddleware',
'guest' => 'App\Http\Middleware\GusetMiddleware',
];
/**
* The application's middleware stack.
*
* @var array
*/
protected $stack = [
'App\Http\Middleware\MaintenanceMiddleware',
'Illuminate\Cookie\Guard',
'Illuminate\Cookie\Queue',
'Illuminate\Session\Middleware\Reader',
'Illuminate\Session\Middleware\Writer',
];
/** /**
* Bootstrap any necessary services. * Bootstrap any necessary services.
* *
...@@ -20,10 +45,7 @@ class AppServiceProvider extends ServiceProvider { ...@@ -20,10 +45,7 @@ class AppServiceProvider extends ServiceProvider {
$this->app->stack(function(Stack $stack, Router $router) $this->app->stack(function(Stack $stack, Router $router)
{ {
return $stack return $stack
->middleware('Illuminate\Cookie\Guard') ->middleware($this->stack)
->middleware('Illuminate\Cookie\Queue')
->middleware('Illuminate\Session\Middlewares\Reader')
->middleware('Illuminate\Session\Middlewares\Writer')
->then(function($request) use ($router) ->then(function($request) use ($router)
{ {
return $router->dispatch($request); return $router->dispatch($request);
......
<?php namespace App\Providers;
use Illuminate\Foundation\Support\Providers\FilterServiceProvider as ServiceProvider;
class FilterServiceProvider extends ServiceProvider {
/**
* The filters that should run before all requests.
*
* @var array
*/
protected $before = [
'App\Http\Filters\MaintenanceFilter',
];
/**
* The filters that should run after all requests.
*
* @var array
*/
protected $after = [
//
];
/**
* All available route filters.
*
* @var array
*/
protected $filters = [
'auth' => 'App\Http\Filters\AuthFilter',
'auth.basic' => 'App\Http\Filters\BasicAuthFilter',
'csrf' => 'App\Http\Filters\CsrfFilter',
'guest' => 'App\Http\Filters\GuestFilter',
];
}
...@@ -102,7 +102,6 @@ return [ ...@@ -102,7 +102,6 @@ return [
'App\Providers\ArtisanServiceProvider', 'App\Providers\ArtisanServiceProvider',
'App\Providers\ErrorServiceProvider', 'App\Providers\ErrorServiceProvider',
'App\Providers\EventServiceProvider', 'App\Providers\EventServiceProvider',
'App\Providers\FilterServiceProvider',
'App\Providers\LogServiceProvider', 'App\Providers\LogServiceProvider',
'App\Providers\RouteServiceProvider', 'App\Providers\RouteServiceProvider',
......
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