mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 15:18:05 +00:00
Various code optimalisations.
This commit is contained in:
@@ -105,7 +105,12 @@ class Authenticate
|
||||
}
|
||||
} catch (QueryException $e) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException('It seems the database has not yet been initialized. Did you run the correct upgrade or installation commands?');
|
||||
throw new FireflyException(
|
||||
sprintf(
|
||||
'It seems the database has not yet been initialized. Did you run the correct upgrade or installation commands? Error: %s',
|
||||
$e->getMessage()
|
||||
)
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@@ -65,6 +66,7 @@ class AuthenticateTwoFactor
|
||||
return response()->redirectTo(route('login'));
|
||||
}
|
||||
|
||||
|
||||
$is2faEnabled = app('preferences')->get('twoFactorAuthEnabled', false)->data;
|
||||
$has2faSecret = null !== app('preferences')->get('twoFactorAuthSecret');
|
||||
$is2faAuthed = 'true' === $request->cookie('twoFactorAuthenticated');
|
||||
|
||||
@@ -30,12 +30,4 @@ use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
*/
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except
|
||||
= [
|
||||
];
|
||||
}
|
||||
|
||||
@@ -48,12 +48,12 @@ class Installer
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (env('APP_ENV') === 'testing') {
|
||||
if ('testing' === env('APP_ENV')) {
|
||||
return $next($request);
|
||||
}
|
||||
$url = $request->url();
|
||||
$strpos = stripos($url, '/install');
|
||||
if (!($strpos === false)) {
|
||||
if (!(false === $strpos)) {
|
||||
Log::debug(sprintf('URL is %s, will NOT run installer middleware', $url));
|
||||
|
||||
return $next($request);
|
||||
@@ -102,7 +102,7 @@ class Installer
|
||||
*/
|
||||
protected function isAccessDenied(string $message): bool
|
||||
{
|
||||
return !(stripos($message, 'Access denied') === false);
|
||||
return !(false === stripos($message, 'Access denied'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,6 +112,6 @@ class Installer
|
||||
*/
|
||||
protected function noTablesExist(string $message): bool
|
||||
{
|
||||
return !(stripos($message, 'Base table or view not found') === false);
|
||||
return !(false === stripos($message, 'Base table or view not found'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -52,7 +53,9 @@ class IsAdmin
|
||||
}
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
if (!$user->hasRole('owner')) {
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
if (!$repository->hasRole($user, 'owner')) {
|
||||
return response()->redirectTo(route('home'));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use FireflyIII\Exceptions\IsDemoUserException;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -48,7 +49,9 @@ class IsDemoUser
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($user->hasRole('demo')) {
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
if ($repository->hasRole($user, 'demo')) {
|
||||
$request->session()->flash('info', (string)trans('firefly.not_available_demo_user'));
|
||||
$current = $request->url();
|
||||
$previous = $request->session()->previousUrl();
|
||||
|
||||
@@ -107,7 +107,7 @@ class Range
|
||||
*/
|
||||
private function loseItAll(Request $request)
|
||||
{
|
||||
if (getenv('DB_CONNECTION') === 'sqlite' && getenv('IS_DOCKER') === true) {
|
||||
if ('sqlite' === getenv('DB_CONNECTION') && true === getenv('IS_DOCKER')) {
|
||||
$request->session()->flash(
|
||||
'error', 'You seem to be using SQLite in a Docker container. Don\'t do this. If the container restarts all your data will be gone.'
|
||||
);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
@@ -51,11 +51,11 @@ class TrustProxies extends Middleware
|
||||
{
|
||||
$trustedProxies = env('TRUSTED_PROXIES', null);
|
||||
if (false !== $trustedProxies && null !== $trustedProxies && \strlen($trustedProxies) > 0) {
|
||||
if ($trustedProxies === '*' || $trustedProxies === '**') {
|
||||
$this->proxies = (string)$trustedProxies;
|
||||
if ('*' === $trustedProxies || '**' === $trustedProxies) {
|
||||
$this->proxies = $trustedProxies;
|
||||
|
||||
}
|
||||
if ($trustedProxies !== '*' && $trustedProxies !== '**') {
|
||||
if ('*' !== $trustedProxies && '**' !== $trustedProxies) {
|
||||
$this->proxies = explode(',', $trustedProxies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,4 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
*/
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except
|
||||
= [
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user