Skip to content

Commit defdd11

Browse files
authored
Merge pull request #869 from sammyskills/fix-inactive-redirect
fix: redirect inactive account to auth action page
2 parents 8ff5ad6 + 91c0025 commit defdd11

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/Filters/SessionAuth.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ public function before(RequestInterface $request, $arguments = null)
6161
}
6262

6363
if ($user !== null && ! $user->isActivated()) {
64-
$authenticator->logout();
65-
66-
return redirect()->route('login')
67-
->with('error', lang('Auth.activationBlocked'));
64+
// If an action has been defined for register, start it up.
65+
$hasAction = $authenticator->startUpAction('register', $user);
66+
if ($hasAction) {
67+
return redirect()->route('auth-action-show')
68+
->with('error', lang('Auth.activationBlocked'));
69+
}
6870
}
6971

7072
return;

tests/Authentication/Filters/AbstractFilterTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static function ($routes): void {
6969
echo 'Open';
7070
});
7171
$routes->get('login', 'AuthController::login', ['as' => 'login']);
72+
$routes->get('auth/a/show', 'AuthActionController::show', ['as' => 'auth-action-show']);
7273
$routes->get('protected-user-route', static function (): void {
7374
echo 'Protected';
7475
}, ['filter' => $this->alias . ':users-read']);

tests/Authentication/Filters/SessionFilterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testRecordActiveDate(): void
5858
$this->assertGreaterThan(auth('session')->user()->updated_at, auth('session')->user()->last_active);
5959
}
6060

61-
public function testBlocksInactiveUsers(): void
61+
public function testBlocksInactiveUsersAndRedirectsToAuthAction(): void
6262
{
6363
$user = fake(UserModel::class, ['active' => false]);
6464

@@ -77,7 +77,7 @@ public function testBlocksInactiveUsers(): void
7777
$result = $this->actingAs($user)
7878
->get('protected-route');
7979

80-
$result->assertRedirectTo('/login');
80+
$result->assertRedirectTo('/auth/a/show');
8181
// User should be logged out
8282
$this->assertNull(auth('session')->id());
8383

0 commit comments

Comments
 (0)