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

65 lines
1.9 KiB
PHP
Raw Normal View History

2016-03-29 11:55:49 +02:00
<?php
/**
* IsNotConfirmed.php
2016-04-01 16:44:46 +02:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-03-29 11:55:49 +02: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-03-29 11:55:49 +02:00
*/
declare(strict_types = 1);
namespace FireflyIII\Http\Middleware;
use Closure;
2016-11-07 18:49:35 +01:00
use FireflyConfig;
2016-03-29 11:55:49 +02:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
2016-12-09 07:20:48 +01:00
use Log;
2016-03-29 11:55:49 +02:00
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);
}
return redirect()->guest('login');
}
// must the user be confirmed in the first place?
2016-11-07 18:49:35 +01:00
$mustConfirmAccount = FireflyConfig::get('must_confirm_account', config('firefly.configuration.must_confirm_account'))->data;
2016-12-09 07:20:48 +01:00
Log::debug(sprintf('mustConfirmAccount is %s', $mustConfirmAccount));
// user must be logged in, then continue:
$isConfirmed = Preferences::get('user_confirmed', false)->data;
2016-12-09 07:20:48 +01:00
Log::debug(sprintf('isConfirmed is %s', $isConfirmed));
2016-11-07 18:49:35 +01:00
if ($isConfirmed || $mustConfirmAccount === false) {
2016-12-09 07:20:48 +01:00
Log::debug('User is confirmed or user does not have to confirm account. Redirect home.');
// user account is confirmed, simply send them home.
return redirect(route('home'));
2016-03-29 11:55:49 +02:00
}
return $next($request);
}
}