Do some more injection on filters.
This commit is contained in:
parent
4e5a151774
commit
34ee58acb6
|
@ -2,10 +2,39 @@
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Route;
|
use Illuminate\Routing\Route;
|
||||||
use Auth, Redirect, Response;
|
use Illuminate\Contracts\Auth\Authenticator;
|
||||||
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||||
|
|
||||||
class AuthFilter {
|
class AuthFilter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The authenticator implementation.
|
||||||
|
*
|
||||||
|
* @var Authenticator
|
||||||
|
*/
|
||||||
|
protected $auth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The response factory implementation.
|
||||||
|
*
|
||||||
|
* @var ResponseFactory
|
||||||
|
*/
|
||||||
|
protected $response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new filter instance.
|
||||||
|
*
|
||||||
|
* @param Authenticator $auth
|
||||||
|
* @param ResponseFactory $response
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Authenticator $auth,
|
||||||
|
ResponseFactory $response)
|
||||||
|
{
|
||||||
|
$this->auth = $auth;
|
||||||
|
$this->response = $response;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the request filter.
|
* Run the request filter.
|
||||||
*
|
*
|
||||||
|
@ -15,15 +44,15 @@ class AuthFilter {
|
||||||
*/
|
*/
|
||||||
public function filter(Route $route, Request $request)
|
public function filter(Route $route, Request $request)
|
||||||
{
|
{
|
||||||
if (Auth::guest())
|
if ($this->auth->guest())
|
||||||
{
|
{
|
||||||
if ($request->ajax())
|
if ($request->ajax())
|
||||||
{
|
{
|
||||||
return Response::make('Unauthorized', 401);
|
return $this->response->make('Unauthorized', 401);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Redirect::guest('auth/login');
|
return $this->response->redirectGuest('auth/login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,27 @@
|
||||||
<?php namespace App\Http\Filters;
|
<?php namespace App\Http\Filters;
|
||||||
|
|
||||||
use Auth;
|
use Illuminate\Contracts\Auth\Authenticator;
|
||||||
|
|
||||||
class BasicAuthFilter {
|
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.
|
* Run the request filter.
|
||||||
*
|
*
|
||||||
|
@ -11,7 +29,7 @@ class BasicAuthFilter {
|
||||||
*/
|
*/
|
||||||
public function filter()
|
public function filter()
|
||||||
{
|
{
|
||||||
return Auth::basic();
|
return $this->auth->basic();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
<?php namespace App\Http\Filters;
|
<?php namespace App\Http\Filters;
|
||||||
|
|
||||||
use Session;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Route;
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Session\TokenMismatchException;
|
use Illuminate\Session\TokenMismatchException;
|
||||||
|
@ -18,7 +17,7 @@ class CsrfFilter {
|
||||||
*/
|
*/
|
||||||
public function filter(Route $route, Request $request)
|
public function filter(Route $route, Request $request)
|
||||||
{
|
{
|
||||||
if (Session::token() != $request->input('_token'))
|
if ($request->getSession()->token() != $request->input('_token'))
|
||||||
{
|
{
|
||||||
throw new TokenMismatchException;
|
throw new TokenMismatchException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?php namespace App\Http\Filters;
|
|
||||||
|
|
||||||
use Auth, Redirect;
|
|
||||||
|
|
||||||
class GuestFilter {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the request filter.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function filter()
|
|
||||||
{
|
|
||||||
if (Auth::check())
|
|
||||||
{
|
|
||||||
return Redirect::to('/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,9 +1,36 @@
|
||||||
<?php namespace App\Http\Filters;
|
<?php namespace App\Http\Filters;
|
||||||
|
|
||||||
use App, Response;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||||
|
|
||||||
class MaintenanceFilter {
|
class MaintenanceFilter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application implementation.
|
||||||
|
*
|
||||||
|
* @var Application
|
||||||
|
*/
|
||||||
|
protected $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The response factory implementation.
|
||||||
|
*
|
||||||
|
* @var ResponseFactory
|
||||||
|
*/
|
||||||
|
protected $response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new filter instance.
|
||||||
|
*
|
||||||
|
* @param Application $app
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Application $app, ResponseFactory $response)
|
||||||
|
{
|
||||||
|
$this->app = $app;
|
||||||
|
$this->response = $response;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the request filter.
|
* Run the request filter.
|
||||||
*
|
*
|
||||||
|
@ -11,9 +38,9 @@ class MaintenanceFilter {
|
||||||
*/
|
*/
|
||||||
public function filter()
|
public function filter()
|
||||||
{
|
{
|
||||||
if (App::isDownForMaintenance())
|
if ($this->app->isDownForMaintenance())
|
||||||
{
|
{
|
||||||
return Response::make('Be right back!');
|
return $this->response->make('Be right back!', 503);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue