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

46 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
namespace FireflyIII\Http\Middleware;
2015-02-05 21:39:52 -06:00
use Closure;
use Illuminate\Http\Request;
2016-02-04 00:28:39 -06:00
use Illuminate\Support\Facades\Auth;
2016-02-07 00:36:31 -06:00
use Session;
/**
* 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 $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 {
return redirect()->guest('login');
}
2016-02-06 15:14:51 -06:00
} else {
2016-02-07 00:36:31 -06:00
if (intval(Auth::user()->blocked) === 1) {
Auth::guard($guard)->logout();
Session::flash('logoutMessage', trans('firefly.block_account_logout'));
return redirect()->guest('login');
}
}
2015-02-11 00:35:10 -06:00
return $next($request);
}
2015-02-05 21:39:52 -06:00
}