Skip to content

Commit 482c715

Browse files
committed
applied code review suggestions on code files
1 parent 2a4d1c3 commit 482c715

3 files changed

Lines changed: 18 additions & 23 deletions

File tree

src/Filters/ForcePasswordResetFilter.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@
1818
class ForcePasswordResetFilter implements FilterInterface
1919
{
2020
/**
21-
* Do whatever processing this filter needs to do.
22-
* By default it should not return anything during
23-
* normal execution. However, when an abnormal state
24-
* is found, it should return an instance of
25-
* CodeIgniter\HTTP\Response. If it does, script
26-
* execution will end and that Response will be
27-
* sent back to the client, allowing for error pages,
28-
* redirects, etc.
21+
* Checks if a logged in user should reset their
22+
* password, and then redirect to the appropriate
23+
* page.
2924
*
3025
* @param array|null $arguments
3126
*
@@ -42,7 +37,7 @@ public function before(RequestInterface $request, $arguments = null)
4237
/** @var Session $authenticator */
4338
$authenticator = auth('session')->getAuthenticator();
4439

45-
if ($authenticator->loggedIn() && auth()->user()->requiresPasswordReset()) {
40+
if ($authenticator->loggedIn() && $authenticator->getUser()->requiresPasswordReset()) {
4641
return redirect()->to(config('Auth')->forcePasswordResetRedirect());
4742
}
4843
}

src/Models/UserIdentityModel.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,35 +333,33 @@ public function revokeAllAccessTokens(User $user): void
333333
* Force password reset for multiple users.
334334
*
335335
* @param int[]|string[] $userIds
336-
*
337-
* @return mixed
338336
*/
339-
public function forceMultiplePasswordReset(array $userIds)
337+
public function forceMultiplePasswordReset(array $userIds): void
340338
{
341339
$this->where(['type' => Session::ID_TYPE_EMAIL_PASSWORD, 'force_reset' => 0]);
342340
$this->whereIn('user_id', $userIds);
343341
$this->set('force_reset', 1);
342+
$return = $this->update();
344343

345-
return $this->update();
344+
return $this->checkQueryReturn($return);
346345
}
347346

348347
/**
349348
* Force global password reset.
350349
* This is useful for enforcing a password reset
351350
* for ALL users incase of a security breach.
352-
*
353-
* @return mixed
354351
*/
355-
public function forceGlobalPasswordReset()
352+
public function forceGlobalPasswordReset(): void
356353
{
357354
$whereFilter = [
358355
'type' => Session::ID_TYPE_EMAIL_PASSWORD,
359356
'force_reset' => 0,
360357
];
361358
$this->where($whereFilter);
362359
$this->set('force_reset', 1);
360+
$return = $this->update();
363361

364-
return $this->update();
362+
return $this->checkQueryReturn($return);
365363
}
366364

367365
public function fake(Generator &$faker): UserIdentity

src/Traits/Resettable.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,38 @@ public function requiresPasswordReset(): bool
2828
/**
2929
* Force password reset
3030
*/
31-
public function forcePasswordReset(): bool
31+
public function forcePasswordReset(): void
3232
{
3333
// Do nothing if user already requires reset
3434
if ($this->requiresPasswordReset()) {
35-
return true;
35+
return;
3636
}
3737

3838
// Set force_reset to true
3939
$identity_model = model(UserIdentityModel::class);
4040
$identity_model->set('force_reset', 1);
4141
$identity_model->where(['user_id' => $this->id, 'type' => Session::ID_TYPE_EMAIL_PASSWORD]);
42+
$result = $identity_model->update();
4243

43-
return $identity_model->update();
44+
return $this->checkQueryReturn($result);
4445
}
4546

4647
/**
4748
* Undo Force password reset
4849
*/
49-
public function undoForcePasswordReset(): bool
50+
public function undoForcePasswordReset(): void
5051
{
5152
// If user doesn't require password reset, do nothing
5253
if ($this->requiresPasswordReset() === false) {
53-
return true;
54+
return;
5455
}
5556

5657
// Set force_reset to false
5758
$identity_model = model(UserIdentityModel::class);
5859
$identity_model->set('force_reset', 0);
5960
$identity_model->where(['user_id' => $this->id, 'type' => Session::ID_TYPE_EMAIL_PASSWORD]);
61+
$return = $identity_model->update();
6062

61-
return $identity_model->update();
63+
return $this->checkQueryReturn($return);
6264
}
6365
}

0 commit comments

Comments
 (0)