Do some more injection on filters.
This commit is contained in:
parent
4e5a151774
commit
34ee58acb6
|
@ -2,30 +2,59 @@
|
|||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Auth, Redirect, Response;
|
||||
use Illuminate\Contracts\Auth\Authenticator;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
|
||||
class AuthFilter {
|
||||
|
||||
/**
|
||||
* Run the request filter.
|
||||
*
|
||||
* @param \Illuminate\Routing\Route $route
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter(Route $route, Request $request)
|
||||
{
|
||||
if (Auth::guest())
|
||||
{
|
||||
if ($request->ajax())
|
||||
{
|
||||
return Response::make('Unauthorized', 401);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Redirect::guest('auth/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param \Illuminate\Routing\Route $route
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter(Route $route, Request $request)
|
||||
{
|
||||
if ($this->auth->guest())
|
||||
{
|
||||
if ($request->ajax())
|
||||
{
|
||||
return $this->response->make('Unauthorized', 401);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->response->redirectGuest('auth/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,27 @@
|
|||
<?php namespace App\Http\Filters;
|
||||
|
||||
use Auth;
|
||||
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.
|
||||
*
|
||||
|
@ -11,7 +29,7 @@ class BasicAuthFilter {
|
|||
*/
|
||||
public function filter()
|
||||
{
|
||||
return Auth::basic();
|
||||
return $this->auth->basic();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?php namespace App\Http\Filters;
|
||||
|
||||
use Session;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
|
@ -13,12 +12,12 @@ class CsrfFilter {
|
|||
* @param \Illuminate\Routing\Route $route
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return void
|
||||
*
|
||||
*
|
||||
* @throws \Illuminate\Session\TokenMismatchException
|
||||
*/
|
||||
public function filter(Route $route, Request $request)
|
||||
{
|
||||
if (Session::token() != $request->input('_token'))
|
||||
if ($request->getSession()->token() != $request->input('_token'))
|
||||
{
|
||||
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;
|
||||
|
||||
use App, Response;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
|
||||
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.
|
||||
*
|
||||
|
@ -11,9 +38,9 @@ class MaintenanceFilter {
|
|||
*/
|
||||
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