Login Loop
CI / ci (push) Canceled after 0s

This commit is contained in:
Stefan Lazic committed 2026-09-05 09:24:09 +01:00
1 parent f11404c574
commit 16c6c28f07
3 files changed
+47 -1

No files matched your search

+5
View File
@@ -34,6 +34,11 @@ administrator. That account can sign in at `/manager/sign-in`, create
businesses, edit their primary domains, and share the one-time owner setup businesses, edit their primary domains, and share the one-time owner setup
link generated during provisioning. link generated during provisioning.
For an existing installation created before this platform/tenant split, the
recorded `initialAdminUserId` account is allowed to sign in once and is
promoted to the platform administrator. No other business owner can use that
upgrade path.
Business provisioning creates the tenant domain, settings, booking rules, Business provisioning creates the tenant domain, settings, booking rules,
opening hours, system roles, owner staff profile, and seven-day owner opening hours, system roles, owner staff profile, and seven-day owner
invitation in one transaction. The owner chooses a password through that invitation in one transaction. The owner chooses a password through that
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Enums\InstallationStatus; use App\Enums\InstallationStatus;
use App\Models\ApplicationInstallation; use App\Models\ApplicationInstallation;
use App\Models\User;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@@ -31,12 +32,34 @@ class PlatformAuthController extends Controller
'password' => ['required', 'string'], 'password' => ['required', 'string'],
]); ]);
if (! Auth::attempt($credentials, $request->boolean('remember')) || ! $request->user()?->isSuperAdmin) { if (! Auth::attempt($credentials, $request->boolean('remember'))) {
Auth::logout(); Auth::logout();
return back()->withErrors(['email' => 'Those platform administrator details do not match our records.'])->onlyInput('email'); return back()->withErrors(['email' => 'Those platform administrator details do not match our records.'])->onlyInput('email');
} }
$user = $request->user();
if (! $user?->isSuperAdmin) {
$installation = ApplicationInstallation::query()
->where('status', InstallationStatus::Installed)
->first();
$canUpgradeLegacyAdmin = ! User::query()->where('isSuperAdmin', true)->exists()
&& $installation?->initialAdminUserId === $user?->id;
if (! $canUpgradeLegacyAdmin) {
Auth::logout();
return back()->withErrors(['email' => 'Those platform administrator details do not match our records.'])->onlyInput('email');
}
// Existing installations created before platform administration
// was separated may have only an initial business owner. Promote
// that exact recorded account once so the migration is usable.
$user->forceFill(['isSuperAdmin' => true])->save();
Auth::setUser($user->fresh());
}
$request->session()->regenerate(); $request->session()->regenerate();
return redirect()->intended(route('manager.dashboard')); return redirect()->intended(route('manager.dashboard'));
+18
View File
@@ -49,4 +49,22 @@ class InstallationTest extends TestCase
$this->assertDatabaseMissing('User', ['email' => 'another@example.test']); $this->assertDatabaseMissing('User', ['email' => 'another@example.test']);
} }
public function test_an_existing_installation_can_upgrade_its_recorded_initial_admin_once(): void
{
$legacyOwner = User::factory()->create(['isSuperAdmin' => false, 'passwordHash' => password_hash('password123', PASSWORD_BCRYPT)]);
ApplicationInstallation::create([
'id' => 'singleton',
'status' => 'INSTALLED',
'installedAt' => now(),
'initialAdminUserId' => $legacyOwner->id,
]);
$this->post('/manager/sign-in', [
'email' => $legacyOwner->email,
'password' => 'password123',
])->assertRedirect(route('manager.dashboard'));
$this->assertDatabaseHas('User', ['id' => $legacyOwner->id, 'isSuperAdmin' => 1]);
}
} }