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

68 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/**
* Authenticate.php
2017-10-21 01:40:00 -05:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 01:40:00 -05:00
* This file is part of Firefly III.
*
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
2017-12-17 07:44:05 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
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;
/**
2017-11-15 05:25:49 -06:00
* Class Authenticate.
*/
2015-02-11 00:35:10 -06:00
class Authenticate
{
/**
* Handle an incoming request.
*
2017-11-15 05:25:49 -06:00
* @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);
}
2016-02-07 00:36:31 -06:00
return redirect()->guest('login');
}
2017-11-15 05:25:49 -06:00
if (1 === intval(auth()->user()->blocked)) {
$message = strval(trans('firefly.block_account_logout'));
2017-11-15 05:25:49 -06:00
if ('email_changed' === auth()->user()->blocked_code) {
$message = strval(trans('firefly.email_changed_logout'));
}
Session::flash('logoutMessage', $message);
Auth::guard($guard)->logout();
return redirect()->guest('login');
}
2015-02-11 00:35:10 -06:00
return $next($request);
}
2015-02-05 21:39:52 -06:00
}