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

59 lines
1.6 KiB
PHP
Raw Normal View History

2016-03-29 04:55:49 -05:00
<?php
2016-04-01 09:44:46 -05:00
declare(strict_types = 1);
2016-03-29 04:55:49 -05:00
/**
* IsNotConfirmed.php
2016-04-01 09:44:46 -05:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-03-29 04:55:49 -05:00
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Preferences;
/**
* Class IsNotConfirmed
*
* @package FireflyIII\Http\Middleware
*/
class IsNotConfirmed
{
/**
* Handle an incoming request. User account must be confirmed for this routine to let
* the user pass.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle(Request $request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('login');
}
} else {
2016-03-29 06:52:51 -05:00
// must the user be confirmed in the first place?
$confirmAccount = env('MUST_CONFIRM_ACCOUNT', false);
2016-03-29 04:55:49 -05:00
// user must be logged in, then continue:
$isConfirmed = Preferences::get('user_confirmed', false)->data;
2016-03-29 06:52:51 -05:00
if ($isConfirmed || $confirmAccount === false) {
2016-03-29 04:55:49 -05:00
// user account is confirmed, simply send them home.
return redirect(route('home'));
}
}
return $next($request);
}
}