mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
Code clean up.
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -29,18 +28,16 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Class Authenticate
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class Authenticate.
|
||||
*/
|
||||
class Authenticate
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -53,9 +50,9 @@ class Authenticate
|
||||
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
if (intval(auth()->user()->blocked) === 1) {
|
||||
if (1 === intval(auth()->user()->blocked)) {
|
||||
$message = strval(trans('firefly.block_account_logout'));
|
||||
if (auth()->user()->blocked_code === 'email_changed') {
|
||||
if ('email_changed' === auth()->user()->blocked_code) {
|
||||
$message = strval(trans('firefly.email_changed_logout'));
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -32,24 +31,21 @@ use Preferences;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Class AuthenticateTwoFactor
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class AuthenticateTwoFactor.
|
||||
*/
|
||||
class AuthenticateTwoFactor
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $guard = null)
|
||||
{
|
||||
|
||||
// do the usual auth, again:
|
||||
if (Auth::guard($guard)->guest()) {
|
||||
if ($request->ajax()) {
|
||||
@@ -59,17 +55,17 @@ class AuthenticateTwoFactor
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
|
||||
if (intval(auth()->user()->blocked) === 1) {
|
||||
if (1 === intval(auth()->user()->blocked)) {
|
||||
Auth::guard($guard)->logout();
|
||||
Session::flash('logoutMessage', trans('firefly.block_account_logout'));
|
||||
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', false)->data;
|
||||
$has2faSecret = !is_null(Preferences::get('twoFactorAuthSecret'));
|
||||
$has2faSecret = null !== Preferences::get('twoFactorAuthSecret');
|
||||
|
||||
// grab 2auth information from cookie, not from session.
|
||||
$is2faAuthed = Cookie::get('twoFactorAuthenticated') === 'true';
|
||||
$is2faAuthed = 'true' === Cookie::get('twoFactorAuthenticated');
|
||||
|
||||
if ($is2faEnabled && $has2faSecret && !$is2faAuthed) {
|
||||
Log::debug('Does not seem to be 2 factor authed, redirect.');
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -28,9 +27,7 @@ use FireflyIII\Support\Domain;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Class Binder
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class Binder.
|
||||
*/
|
||||
class Binder
|
||||
{
|
||||
@@ -47,8 +44,8 @@ class Binder
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@@ -18,10 +18,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* EncryptCookies.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
@@ -44,6 +42,5 @@ class EncryptCookies extends Middleware
|
||||
*/
|
||||
protected $except
|
||||
= [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -29,18 +28,16 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Class IsAdmin
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class IsAdmin.
|
||||
*/
|
||||
class IsAdmin
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request. Must be admin.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -30,18 +29,16 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Class IsAdmin
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class IsAdmin.
|
||||
*/
|
||||
class IsLimitedUser
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request. May not be a limited user (ie. Sandstorm env. or demo user).
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -62,7 +59,7 @@ class IsLimitedUser
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
if (intval(getenv('SANDSTORM')) === 1) {
|
||||
if (1 === intval(getenv('SANDSTORM'))) {
|
||||
Session::flash('warning', strval(trans('firefly.sandstorm_not_available')));
|
||||
|
||||
return redirect(route('index'));
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -36,9 +35,7 @@ use Session;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class SessionFilter
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class SessionFilter.
|
||||
*/
|
||||
class Range
|
||||
{
|
||||
@@ -52,8 +49,7 @@ class Range
|
||||
/**
|
||||
* Create a new filter instance.
|
||||
*
|
||||
* @param Guard $auth
|
||||
*
|
||||
* @param Guard $auth
|
||||
*/
|
||||
public function __construct(Guard $auth)
|
||||
{
|
||||
@@ -63,16 +59,15 @@ class Range
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
* @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()) {
|
||||
|
||||
// set start, end and finish:
|
||||
$this->setRange();
|
||||
|
||||
@@ -108,11 +103,10 @@ class Range
|
||||
$moneyResult = setlocale(LC_MONETARY, $locale);
|
||||
|
||||
// send error to view if could not set money format
|
||||
if ($moneyResult === false) {
|
||||
if (false === $moneyResult) {
|
||||
View::share('invalidMonetaryLocale', true);
|
||||
}
|
||||
|
||||
|
||||
// save some formats:
|
||||
$monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
$dateTimeFormat = (string)trans('config.date_time');
|
||||
@@ -144,7 +138,7 @@ class Range
|
||||
$journal = $repository->first();
|
||||
$first = Carbon::now()->startOfYear();
|
||||
|
||||
if (!is_null($journal->id)) {
|
||||
if (null !== $journal->id) {
|
||||
$first = $journal->date;
|
||||
}
|
||||
Session::put('first', $first);
|
||||
|
@@ -18,10 +18,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* RedirectIfAuthenticated.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
@@ -41,9 +39,9 @@ class RedirectIfAuthenticated
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -29,18 +28,16 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class RedirectIfTwoFactorAuthenticated
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class RedirectIfTwoFactorAuthenticated.
|
||||
*/
|
||||
class RedirectIfTwoFactorAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -48,10 +45,10 @@ class RedirectIfTwoFactorAuthenticated
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', false)->data;
|
||||
$has2faSecret = !is_null(Preferences::get('twoFactorAuthSecret'));
|
||||
$has2faSecret = null !== Preferences::get('twoFactorAuthSecret');
|
||||
|
||||
// grab 2auth information from cookie
|
||||
$is2faAuthed = Cookie::get('twoFactorAuthenticated') === 'true';
|
||||
$is2faAuthed = 'true' === Cookie::get('twoFactorAuthenticated');
|
||||
|
||||
if ($is2faEnabled && $has2faSecret && $is2faAuthed) {
|
||||
return redirect('/');
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -33,9 +32,7 @@ use Illuminate\Http\Request;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class Sandstorm
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class Sandstorm.
|
||||
*/
|
||||
class Sandstorm
|
||||
{
|
||||
@@ -43,18 +40,19 @@ class Sandstorm
|
||||
* Detects if is using Sandstorm, and responds by logging the user
|
||||
* in and/or creating an account.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $guard = null)
|
||||
{
|
||||
// is in Sandstorm environment?
|
||||
$sandstorm = intval(getenv('SANDSTORM')) === 1;
|
||||
$sandstorm = 1 === intval(getenv('SANDSTORM'));
|
||||
View::share('SANDSTORM', $sandstorm);
|
||||
if (!$sandstorm) {
|
||||
return $next($request);
|
||||
@@ -72,7 +70,7 @@ class Sandstorm
|
||||
// access the same data so we have no choice but to simply login
|
||||
// the new user to the same account and just forget about Bob and Alice
|
||||
// and any other differences there may be between these users.
|
||||
if ($count === 1 && strlen($userId) > 0) {
|
||||
if (1 === $count && strlen($userId) > 0) {
|
||||
// login as first user user.
|
||||
$user = User::first();
|
||||
Auth::guard($guard)->login($user);
|
||||
@@ -81,7 +79,7 @@ class Sandstorm
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($count === 1 && strlen($userId) === 0) {
|
||||
if (1 === $count && 0 === strlen($userId)) {
|
||||
// login but indicate anonymous
|
||||
$user = User::first();
|
||||
Auth::guard($guard)->login($user);
|
||||
@@ -90,7 +88,7 @@ class Sandstorm
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($count === 0 && strlen($userId) > 0) {
|
||||
if (0 === $count && strlen($userId) > 0) {
|
||||
// create new user.
|
||||
$email = $userId . '@firefly';
|
||||
/** @var User $user */
|
||||
@@ -110,7 +108,7 @@ class Sandstorm
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($count === 0 && strlen($userId) === 0) {
|
||||
if (0 === $count && 0 === strlen($userId)) {
|
||||
throw new FireflyException('The first visit to a new Firefly III administration cannot be by a guest user.');
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -28,17 +27,15 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
|
||||
/**
|
||||
* Class StartFireflySession
|
||||
*
|
||||
* @package FireflyIII\Http\Middleware
|
||||
* Class StartFireflySession.
|
||||
*/
|
||||
class StartFireflySession extends StartSession
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Closure $next
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -50,16 +47,14 @@ class StartFireflySession extends StartSession
|
||||
/**
|
||||
* Store the current URL for the request if necessary.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Contracts\Session\Session $session
|
||||
*
|
||||
* @return void
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Contracts\Session\Session $session
|
||||
*/
|
||||
protected function storeCurrentUrl(Request $request, $session)
|
||||
{
|
||||
$uri = $request->fullUrl();
|
||||
$strpos = strpos($uri, 'jscript');
|
||||
if ($request->method() === 'GET' && $request->route() && !$request->ajax() && $strpos === false) {
|
||||
if ('GET' === $request->method() && $request->route() && !$request->ajax() && false === $strpos) {
|
||||
$session->setPreviousUrl($uri);
|
||||
}
|
||||
}
|
||||
|
@@ -18,10 +18,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* TrimStrings.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
|
@@ -18,10 +18,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* TrustProxies.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
@@ -67,7 +65,7 @@ class TrustProxies extends Middleware
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
$trustedProxies = env('TRUSTED_PROXIES', null);
|
||||
if (!is_null($trustedProxies) && strlen($trustedProxies) > 0) {
|
||||
if (null !== $trustedProxies && strlen($trustedProxies) > 0) {
|
||||
$this->proxies = $trustedProxies;
|
||||
}
|
||||
|
||||
|
@@ -18,10 +18,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* VerifyCsrfToken.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
@@ -44,6 +42,5 @@ class VerifyCsrfToken extends Middleware
|
||||
*/
|
||||
protected $except
|
||||
= [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user