mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-02-21 04:14:24 +01:00
Add middleware
This commit is contained in:
parent
261b6abb18
commit
ec93ebb8fe
3 changed files with 33 additions and 9 deletions
|
@ -29,5 +29,6 @@ class Kernel extends HttpKernel
|
||||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||||
|
'csrf' => \App\Http\Middleware\VerifyCsrfHeader::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ class Authenticate
|
||||||
* Create a new filter instance.
|
* Create a new filter instance.
|
||||||
*
|
*
|
||||||
* @param Guard $auth
|
* @param Guard $auth
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Guard $auth)
|
public function __construct(Guard $auth)
|
||||||
{
|
{
|
||||||
|
@ -35,11 +34,7 @@ class Authenticate
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
if ($this->auth->guest()) {
|
if ($this->auth->guest()) {
|
||||||
if ($request->ajax()) {
|
return redirect()->guest('login');
|
||||||
return response('Unauthorized.', 401);
|
|
||||||
} else {
|
|
||||||
return redirect()->guest('auth/login');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|
28
app/Http/Middleware/VerifyCsrfHeader.php
Normal file
28
app/Http/Middleware/VerifyCsrfHeader.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Session\TokenMismatchException;
|
||||||
|
use Session;
|
||||||
|
|
||||||
|
class VerifyCsrfHeader
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
* @throws TokenMismatchException
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
if (Session::token() != $request->input('_token') && Session::token() != $request->header('X-Token')) {
|
||||||
|
throw new TokenMismatchException;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue