Skip to content

Commit cbfef1a

Browse files
committed
fix: handle password reset checks without a password identity
1 parent 636190e commit cbfef1a

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎docs/user_management/forcing_password_reset.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ the following methods to do so.
2828

2929
### Check if a User Requires Password Reset
3030

31-
When you need to check if a user requires password reset, you can do so using the `requiresPasswordReset()` method on the `User` entity. Returns boolean `true`/`false`.
31+
Call `requiresPasswordReset()` on the `User` entity to check whether its
32+
email/password identity requires a password reset. The method returns `false`
33+
for users without an email/password identity. These users can continue through
34+
the `force-reset` filter.
3235

3336
```php
3437
if ($user->requiresPasswordReset()) {

‎src/Traits/Resettable.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
trait Resettable
2424
{
2525
/**
26-
* Returns true|false based on the value of the
27-
* force reset column of the user's identity.
26+
* Checks whether the user's email/password identity requires a password reset.
27+
* A user without that identity does not require a Shield password reset.
2828
*/
2929
public function requiresPasswordReset(): bool
3030
{
3131
$identityModel = model(UserIdentityModel::class);
3232
$identity = $identityModel->getIdentityByType($this, Session::ID_TYPE_EMAIL_PASSWORD);
3333

34-
return $identity->force_reset;
34+
return $identity->force_reset ?? false;
3535
}
3636

3737
/**

‎tests/Authentication/ForcePasswordResetTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ public function testUserRequiresPasswordReset(): void
6262
$this->assertTrue($user->requiresPasswordReset());
6363
}
6464

65+
public function testUserWithoutEmailPasswordIdentityDoesNotRequirePasswordReset(): void
66+
{
67+
$user = fake(UserModel::class);
68+
69+
$this->assertFalse($user->requiresPasswordReset());
70+
}
71+
72+
public function testForceResetFilterAllowsUserWithoutEmailPasswordIdentity(): void
73+
{
74+
$user = fake(UserModel::class);
75+
76+
$result = $this->actingAs($user)->get('profile');
77+
78+
$result->assertStatus(200);
79+
$result->assertSee('Profile');
80+
}
81+
6582
public function testForcePasswordResetOnUser(): void
6683
{
6784
$user = fake(UserModel::class);

0 commit comments

Comments
 (0)