2016-01-08 09:00:57 -06:00
|
|
|
<?php
|
2016-05-20 05:41:23 -05:00
|
|
|
/**
|
|
|
|
* Authenticate.php
|
2017-10-21 01:40:00 -05:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-05-20 05:41:23 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* This file is part of Firefly III.
|
2016-10-04 23:52:15 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-20 05:41:23 -05:00
|
|
|
*/
|
|
|
|
|
2017-04-09 00:44:22 -05: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) {
|
2017-09-26 01:52:16 -05:00
|
|
|
$message = strval(trans('firefly.block_account_logout'));
|
|
|
|
if (auth()->user()->blocked_code === 'email_changed') {
|
|
|
|
$message = strval(trans('firefly.email_changed_logout'));
|
|
|
|
}
|
|
|
|
|
|
|
|
Session::flash('logoutMessage', $message);
|
2016-05-20 10:53:03 -05:00
|
|
|
Auth::guard($guard)->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
|
|
|
}
|