mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-12-06 17:52:16 +00:00
Allow remember-me for passwordless users
This commit is contained in:
@@ -183,6 +183,15 @@ class User extends Authenticatable implements AuditableContract, FilamentUser, M
|
||||
$this->notify(new ResetPassword($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* Passwordless (SSO-only) users have no hash; Laravel rejects remember-me cookies of users without one, so
|
||||
* they get an empty string, which no password ever matches.
|
||||
*/
|
||||
public function getAuthPassword(): string
|
||||
{
|
||||
return is_string($this->password) ? $this->password : '';
|
||||
}
|
||||
|
||||
public function hasLocalPassword(): bool
|
||||
{
|
||||
return is_string($this->password) && $this->password !== '';
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Enums\Role;
|
||||
use App\Http\Controllers\Web\DashboardController;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
|
||||
@@ -27,6 +28,20 @@ class DashboardEndpointTest extends EndpointTestAbstract
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_remember_me_cookie_signs_in_a_passwordless_user(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->withPersonalOrganization()->create(['password' => null]);
|
||||
$guard = Auth::guard('web');
|
||||
$recaller = $user->getKey().'|'.$user->getRememberToken().'|'.$guard->hashPasswordForCookie($user->getAuthPassword());
|
||||
|
||||
// Act
|
||||
$this->withCookie($guard->getRecallerName(), $recaller)->get('/dashboard');
|
||||
|
||||
// Assert
|
||||
$this->assertAuthenticatedAs($user);
|
||||
}
|
||||
|
||||
public function test_showing_dashboard_succeeds_for_user_with_employee_role(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -16,6 +16,7 @@ use App\Models\User;
|
||||
use App\Providers\Filament\AdminPanelProvider;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
|
||||
#[CoversClass(User::class)]
|
||||
@@ -283,4 +284,17 @@ class UserModelTest extends ModelTestAbstract
|
||||
$authCodesRel->pluck('id')->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_passwordless_user_has_an_empty_auth_password_that_no_password_matches(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->create(['password' => null]);
|
||||
|
||||
// Act
|
||||
$authPassword = $user->getAuthPassword();
|
||||
|
||||
// Assert
|
||||
$this->assertSame('', $authPassword);
|
||||
$this->assertFalse(Hash::check('', $authPassword));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user