mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve testing of middleware.
This commit is contained in:
@@ -89,6 +89,9 @@ class Range
|
||||
View::share('listLength', $pref);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function configureView()
|
||||
{
|
||||
$pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
|
||||
@@ -103,7 +106,7 @@ class Range
|
||||
|
||||
// send error to view if could not set money format
|
||||
if (false === $moneyResult) {
|
||||
View::share('invalidMonetaryLocale', true);
|
||||
View::share('invalidMonetaryLocale', true); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// save some formats:
|
||||
|
@@ -43,7 +43,7 @@ class RedirectIfAuthenticated
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect('/home');
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@@ -44,13 +44,14 @@ class RedirectIfTwoFactorAuthenticated
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', false)->data;
|
||||
|
||||
$has2faSecret = null !== Preferences::get('twoFactorAuthSecret');
|
||||
|
||||
// grab 2auth information from cookie.
|
||||
$is2faAuthed = 'true' === $request->cookie('twoFactorAuthenticated');
|
||||
|
||||
if ($is2faEnabled && $has2faSecret && $is2faAuthed) {
|
||||
return redirect('/');
|
||||
return redirect(route('index'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,10 +25,10 @@ namespace FireflyIII\Http\Middleware;
|
||||
use Auth;
|
||||
use Closure;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Role;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,8 @@ class Sandstorm
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
$userId = strval($request->header('X-Sandstorm-User-Id'));
|
||||
$count = $repository->count();
|
||||
Log::debug(sprintf('Sandstorm user ID is "%s"', $userId));
|
||||
$count = $repository->count();
|
||||
|
||||
// if there already is one user in this instance, we assume this is
|
||||
// the "main" user. Firefly's nature does not allow other users to
|
||||
@@ -72,7 +73,7 @@ class Sandstorm
|
||||
// and any other differences there may be between these users.
|
||||
if (1 === $count && strlen($userId) > 0) {
|
||||
// login as first user user.
|
||||
$user = User::first();
|
||||
$user = $repository->first();
|
||||
Auth::guard($guard)->login($user);
|
||||
View::share('SANDSTORM_ANON', false);
|
||||
|
||||
@@ -92,7 +93,7 @@ class Sandstorm
|
||||
// create new user.
|
||||
$email = $userId . '@firefly';
|
||||
/** @var User $user */
|
||||
$user = User::create(
|
||||
$user = $repository->store(
|
||||
[
|
||||
'email' => $email,
|
||||
'password' => str_random(16),
|
||||
@@ -101,9 +102,10 @@ class Sandstorm
|
||||
Auth::guard($guard)->login($user);
|
||||
|
||||
// also make the user an admin
|
||||
$admin = Role::where('name', 'owner')->first();
|
||||
$user->attachRole($admin);
|
||||
$user->save();
|
||||
$repository->attachRole($user, 'owner');
|
||||
|
||||
// share value.
|
||||
View::share('SANDSTORM_ANON', false);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@@ -116,6 +118,14 @@ class Sandstorm
|
||||
throw new FireflyException('Your Firefly III installation has more than one user, which is weird.');
|
||||
}
|
||||
}
|
||||
// if in Sandstorm, user logged in, still must check if user is anon.
|
||||
$userId = strval($request->header('X-Sandstorm-User-Id'));
|
||||
if (strlen($userId) === 0) {
|
||||
View::share('SANDSTORM_ANON', true);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
View::share('SANDSTORM_ANON', false);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
Reference in New Issue
Block a user