Working on stack.
This commit is contained in:
parent
2893433b35
commit
d2937ea714
|
@ -1,35 +0,0 @@
|
||||||
<?php namespace App\Http\Filters;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Auth\Authenticator;
|
|
||||||
|
|
||||||
class BasicAuthFilter {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The authenticator implementation.
|
|
||||||
*
|
|
||||||
* @var Authenticator
|
|
||||||
*/
|
|
||||||
protected $auth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new filter instance.
|
|
||||||
*
|
|
||||||
* @param Authenticator $auth
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(Authenticator $auth)
|
|
||||||
{
|
|
||||||
$this->auth = $auth;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the request filter.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function filter()
|
|
||||||
{
|
|
||||||
return $this->auth->basic();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
<?php namespace App\Http\Filters;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Routing\Route;
|
|
||||||
use Illuminate\Session\TokenMismatchException;
|
|
||||||
|
|
||||||
class CsrfFilter {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the request filter.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Routing\Route $route
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws \Illuminate\Session\TokenMismatchException
|
|
||||||
*/
|
|
||||||
public function filter(Route $route, Request $request)
|
|
||||||
{
|
|
||||||
if ($request->getSession()->token() != $request->input('_token'))
|
|
||||||
{
|
|
||||||
throw new TokenMismatchException;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,11 +1,12 @@
|
||||||
<?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 @@ public function __construct(Authenticator $auth,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 @@ public function filter(Route $route, Request $request)
|
||||||
return $this->response->redirectGuest('auth/login');
|
return $this->response->redirectGuest('auth/login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Contracts\Routing\Middleware;
|
||||||
|
use Illuminate\Contracts\Auth\Authenticator;
|
||||||
|
|
||||||
|
class BasicAuthMiddleware implements Middleware {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The authenticator implementation.
|
||||||
|
*
|
||||||
|
* @var Authenticator
|
||||||
|
*/
|
||||||
|
protected $auth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new filter instance.
|
||||||
|
*
|
||||||
|
* @param Authenticator $auth
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Authenticator $auth)
|
||||||
|
{
|
||||||
|
$this->auth = $auth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
return $this->auth->basic() ?: $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Contracts\Routing\Middleware;
|
||||||
|
use Illuminate\Session\TokenMismatchException;
|
||||||
|
|
||||||
|
class CsrfMiddleware implements Middleware {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
if ($request->getSession()->token() != $request->input('_token'))
|
||||||
|
{
|
||||||
|
throw new TokenMismatchException;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
<?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 @@ public function __construct(Authenticator $auth)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
<?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 @@ public function __construct(Application $app)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 @@
|
||||||
|
|
||||||
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 @@ public function boot()
|
||||||
$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);
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
<?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 @@
|
||||||
'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',
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue