firefly-iii/app/Http/Middleware/Authenticate.php

38 lines
764 B
PHP
Raw Normal View History

<?php
namespace FireflyIII\Http\Middleware;
2015-02-05 21:39:52 -06:00
use Closure;
use Illuminate\Support\Facades\Auth;
2015-12-18 09:38:50 -06:00
/**
* Class Authenticate
*
* @package FireflyIII\Http\Middleware
*/
2015-02-11 00:35:10 -06:00
class Authenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
2015-02-11 00:35:10 -06:00
*
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
2015-02-11 00:35:10 -06:00
{
if (Auth::guard($guard)->guest()) {
2015-02-11 00:35:10 -06:00
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
2015-12-18 09:38:50 -06:00
return redirect()->guest('login');
}
}
2015-02-11 00:35:10 -06:00
return $next($request);
}
2015-02-05 21:39:52 -06:00
}