Skip to content

Commit e41939c

Browse files
Enhance password reset flow to include checks for inactive user
1 parent 7e6b7b5 commit e41939c

5 files changed

Lines changed: 69 additions & 4 deletions

File tree

ProcessMaker/Http/Controllers/Auth/ForgotPasswordController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct()
3535

3636
/**
3737
* Send a reset link to the given user.
38-
* Blocked users will not receive the reset email for security reasons.
38+
* Blocked or inactive users will not receive the reset email for security reasons.
3939
*
4040
* @param Request $request
4141
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
@@ -46,7 +46,7 @@ public function sendResetLinkEmail(Request $request)
4646

4747
$user = User::where('email', $request->input('email'))->first();
4848

49-
if ($user && $user->status === 'BLOCKED') {
49+
if ($user && ($user->status === 'BLOCKED' || $user->status === 'INACTIVE')) {
5050
return $this->sendResetLinkResponse($request, Password::RESET_LINK_SENT);
5151
}
5252

ProcessMaker/Http/Controllers/Auth/ResetPasswordController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public function showResetForm(Request $request, $token)
5555
->withErrors(['email' => __('passwords.blocked')]);
5656
}
5757

58+
if ($user->status === 'INACTIVE') {
59+
return redirect()->route('password.request')
60+
->withErrors(['email' => __('passwords.inactive')]);
61+
}
62+
5863
return view('auth.passwords.reset', [
5964
'username' => $user->username,
6065
'token' => $token,
@@ -64,7 +69,7 @@ public function showResetForm(Request $request, $token)
6469

6570
/**
6671
* Reset the given user's password.
67-
* Blocked users cannot reset their password.
72+
* Blocked or inactive users cannot reset their password.
6873
*
6974
* @param Request $request
7075
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
@@ -77,6 +82,10 @@ public function reset(Request $request)
7782
return $this->sendResetFailedResponse($request, 'passwords.blocked');
7883
}
7984

85+
if ($user && $user->status === 'INACTIVE') {
86+
return $this->sendResetFailedResponse($request, 'passwords.inactive');
87+
}
88+
8089
return $this->performPasswordReset($request);
8190
}
8291
}

resources/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,7 @@
15471547
"passwords.token": "This password reset token is invalid.",
15481548
"passwords.user": "We can't find a user with that e-mail address.",
15491549
"passwords.blocked": "Your account has been blocked. Please contact your administrator.",
1550+
"passwords.inactive": "Your account is inactive. Please contact your administrator.",
15501551
"Pause Start Timer Events": "Pause Start Timer Events",
15511552
"Pause Timer Start Events": "Pause Timer Start Events",
15521553
"per page": "per page",

resources/lang/en/passwords.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
'token' => 'This password reset token is invalid.',
2020
'user' => "We can't find a user with that email address.",
2121
'blocked' => 'Your account has been blocked. Please contact your administrator.',
22+
'inactive' => 'Your account is inactive. Please contact your administrator.',
2223

2324
];

tests/Feature/Auth/PasswordResetTest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ public function testForgotPasswordDoesNotNotifyBlockedUser(): void
2929
Notification::assertNothingSent();
3030
}
3131

32+
public function testForgotPasswordDoesNotNotifyInactiveUser(): void
33+
{
34+
Notification::fake();
35+
36+
$user = User::factory()->create([
37+
'email' => 'inactive-forgot@example.com',
38+
'status' => 'INACTIVE',
39+
]);
40+
41+
$response = $this->post(route('password.email'), [
42+
'email' => $user->email,
43+
]);
44+
45+
$response->assertSessionHas('status');
46+
Notification::assertNothingSent();
47+
}
48+
3249
public function testForgotPasswordSendsNotificationToActiveUser(): void
3350
{
3451
Notification::fake();
@@ -57,7 +74,25 @@ public function testShowResetFormRedirectsBlockedUserToRequestForm(): void
5774
$response = $this->get($url . '?email=' . urlencode($user->email));
5875

5976
$response->assertRedirect(route('password.request'));
60-
$response->assertSessionHasErrors('email');
77+
$response->assertSessionHasErrors([
78+
'email' => __('passwords.blocked'),
79+
]);
80+
}
81+
82+
public function testShowResetFormRedirectsInactiveUserToRequestForm(): void
83+
{
84+
$user = User::factory()->create([
85+
'email' => 'inactive-reset-form@example.com',
86+
'status' => 'INACTIVE',
87+
]);
88+
89+
$url = route('password.reset', ['token' => 'unused-token']);
90+
$response = $this->get($url . '?email=' . urlencode($user->email));
91+
92+
$response->assertRedirect(route('password.request'));
93+
$response->assertSessionHasErrors([
94+
'email' => __('passwords.inactive'),
95+
]);
6196
}
6297

6398
public function testShowResetFormDisplaysForActiveUser(): void
@@ -97,6 +132,25 @@ public function testResetPasswordRejectsBlockedUser(): void
97132
]);
98133
}
99134

135+
public function testResetPasswordRejectsInactiveUser(): void
136+
{
137+
$user = User::factory()->create([
138+
'email' => 'inactive-reset-post@example.com',
139+
'status' => 'INACTIVE',
140+
]);
141+
142+
$response = $this->from(route('password.request'))->post('/password/reset', [
143+
'token' => 'will-not-be-used',
144+
'email' => $user->email,
145+
'password' => 'NewPassword123!',
146+
'password_confirmation' => 'NewPassword123!',
147+
]);
148+
149+
$response->assertSessionHasErrors([
150+
'email' => __('passwords.inactive'),
151+
]);
152+
}
153+
100154
public function testResetPasswordUpdatesPasswordForActiveUser(): void
101155
{
102156
/** @var User $user */

0 commit comments

Comments
 (0)