2016-01-08 09:00:57 -06:00
|
|
|
<?php
|
2016-05-20 05:41:23 -05:00
|
|
|
/**
|
|
|
|
* Authenticate.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-04 23:52:15 -05:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 05:41:23 -05:00
|
|
|
*/
|
|
|
|
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2016-01-08 09:00:57 -06:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Middleware;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
|
|
|
use Closure;
|
2016-01-28 14:33:45 -06:00
|
|
|
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;
|
2016-03-14 14:53:56 -05:00
|
|
|
|
2016-01-09 01:20:55 -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
|
2016-01-08 09:00:57 -06:00
|
|
|
* @param string|null $guard
|
2015-02-11 00:35:10 -06:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-01-28 14:33:45 -06:00
|
|
|
public function handle(Request $request, Closure $next, $guard = null)
|
2015-02-11 00:35:10 -06:00
|
|
|
{
|
2016-01-08 09:00:57 -06:00
|
|
|
if (Auth::guard($guard)->guest()) {
|
2015-02-11 00:35:10 -06:00
|
|
|
if ($request->ajax()) {
|
|
|
|
return response('Unauthorized.', 401);
|
2016-01-08 09:00:57 -06:00
|
|
|
}
|
2016-02-07 00:36:31 -06:00
|
|
|
|
2016-05-20 10:53:03 -05:00
|
|
|
return redirect()->guest('login');
|
|
|
|
}
|
2016-09-16 05:15:58 -05:00
|
|
|
if (intval(auth()->user()->blocked) === 1) {
|
2016-05-20 10:53:03 -05:00
|
|
|
Auth::guard($guard)->logout();
|
|
|
|
Session::flash('logoutMessage', trans('firefly.block_account_logout'));
|
|
|
|
|
|
|
|
return redirect()->guest('login');
|
2015-07-24 06:17:47 -05:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
return $next($request);
|
|
|
|
}
|
2015-02-05 21:39:52 -06:00
|
|
|
}
|