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

56 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/**
* Authenticate.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* 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-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);
}
2016-02-07 00:36:31 -06:00
return redirect()->guest('login');
}
2016-09-16 05:15:58 -05: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
}