Update middleware after upgrade to Laravel 5.2

This commit is contained in:
James Cole 2016-01-08 16:00:57 +01:00
parent bbd19be554
commit ba32a665f1
6 changed files with 47 additions and 152 deletions

52
app/Http/Middleware/Authenticate.php Normal file → Executable file
View File

@ -1,65 +1,33 @@
<?php namespace FireflyIII\Http\Middleware;
<?php
namespace FireflyIII\Http\Middleware;
use App;
use Auth;
use Carbon\Carbon;
use Closure;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Preferences;
/**
* Class Authenticate
*
* @codeCoverageIgnore
* @package FireflyIII\Http\Middleware
*/
class Authenticate
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
*
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guest()) {
if (Auth::guard($guard)->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}
/** @var User $user */
$user = $this->auth->user();
if ($user instanceof User && intval($user->blocked) == 1) {
Auth::logout();
return redirect()->route('index');
return redirect()->guest('login');
}
}
// if logged in, set user language:
@ -72,7 +40,7 @@ class Authenticate
setlocale(LC_TIME, $locale);
setlocale(LC_MONETARY, $locale);
return $next($request);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace FireflyIII\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
class EncryptCookies extends BaseEncrypter
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
//
];
}

View File

@ -45,7 +45,7 @@ class Range
*
* @return mixed
*/
public function handle(Request $request, Closure $theNext)
public function handle($request, Closure $theNext, $guard = null)
{
if ($this->auth->check()) {

43
app/Http/Middleware/RedirectIfAuthenticated.php Normal file → Executable file
View File

@ -1,52 +1,29 @@
<?php namespace FireflyIII\Http\Middleware;
<?php
namespace FireflyIII\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Log;
/**
* Class RedirectIfAuthenticated
*
* @codeCoverageIgnore
* @package FireflyIII\Http\Middleware
*/
class RedirectIfAuthenticated
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
*
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->check()) {
return new RedirectResponse(url('/'));
if (Auth::guard($guard)->check()) {
return redirect('/');
}
return $next($request);
}
}

View File

@ -1,57 +0,0 @@
<?php
namespace FireflyIII\Http\Middleware;
use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Log;
/**
* Class ReplaceTestVars
*
* @codeCoverageIgnore
* @package FireflyIII\Http\Middleware
*/
class ReplaceTestVars
{
/**
* The application implementation.
*
* @var Application
*/
protected $app;
/**
* Create a new filter instance.
*
* @param Application $app
*
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if ('testing' === $this->app->environment() && $request->has('_token')) {
$input = $request->all();
$input['_token'] = $request->session()->token();
// we need to update _token value to make sure we get the POST / PUT tests passed.
Log::debug('Input token replaced (' . $input['_token'] . ').');
$request->replace($input);
}
return $next($request);
}
}

View File

@ -1,27 +1,17 @@
<?php namespace FireflyIII\Http\Middleware;
<?php
namespace FireflyIII\Http\Middleware;
use Closure;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
/**
* Class VerifyCsrfToken
*
* @codeCoverageIgnore
* @package FireflyIII\Http\Middleware
*/
class VerifyCsrfToken extends BaseVerifier
{
/**
* Handle an incoming request.
* The URIs that should be excluded from CSRF verification.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
* @var array
*/
public function handle($request, Closure $next)
{
return parent::handle($request, $next);
}
protected $except
= [
//
];
}