From 164bce403e10c5fccc5a7ca148b4b8193c8fa9c9 Mon Sep 17 00:00:00 2001 From: Samuel Asor <8720569+sammyskills@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:52:55 +0100 Subject: [PATCH 1/2] redirect inactive account to auth action --- src/Filters/SessionAuth.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Filters/SessionAuth.php b/src/Filters/SessionAuth.php index 6a8a0d8fe..b7d449666 100644 --- a/src/Filters/SessionAuth.php +++ b/src/Filters/SessionAuth.php @@ -61,10 +61,12 @@ public function before(RequestInterface $request, $arguments = null) } if ($user !== null && ! $user->isActivated()) { - $authenticator->logout(); - - return redirect()->route('login') - ->with('error', lang('Auth.activationBlocked')); + // If an action has been defined for register, start it up. + $hasAction = $authenticator->startUpAction('register', $user); + if ($hasAction) { + return redirect()->route('auth-action-show') + ->with('error', lang('Auth.activationBlocked')); + } } return; From 91c00259bbe0ea9e205da88e946efed6011943b1 Mon Sep 17 00:00:00 2001 From: Samuel Asor <8720569+sammyskills@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:53:55 +0100 Subject: [PATCH 2/2] added tests --- tests/Authentication/Filters/AbstractFilterTestCase.php | 1 + tests/Authentication/Filters/SessionFilterTest.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Authentication/Filters/AbstractFilterTestCase.php b/tests/Authentication/Filters/AbstractFilterTestCase.php index 23ece0925..d44f9e931 100644 --- a/tests/Authentication/Filters/AbstractFilterTestCase.php +++ b/tests/Authentication/Filters/AbstractFilterTestCase.php @@ -69,6 +69,7 @@ static function ($routes): void { echo 'Open'; }); $routes->get('login', 'AuthController::login', ['as' => 'login']); + $routes->get('auth/a/show', 'AuthActionController::show', ['as' => 'auth-action-show']); $routes->get('protected-user-route', static function (): void { echo 'Protected'; }, ['filter' => $this->alias . ':users-read']); diff --git a/tests/Authentication/Filters/SessionFilterTest.php b/tests/Authentication/Filters/SessionFilterTest.php index 1b379ccc3..a217d7a74 100644 --- a/tests/Authentication/Filters/SessionFilterTest.php +++ b/tests/Authentication/Filters/SessionFilterTest.php @@ -58,7 +58,7 @@ public function testRecordActiveDate(): void $this->assertGreaterThan(auth('session')->user()->updated_at, auth('session')->user()->last_active); } - public function testBlocksInactiveUsers(): void + public function testBlocksInactiveUsersAndRedirectsToAuthAction(): void { $user = fake(UserModel::class, ['active' => false]); @@ -77,7 +77,7 @@ public function testBlocksInactiveUsers(): void $result = $this->actingAs($user) ->get('protected-route'); - $result->assertRedirectTo('/login'); + $result->assertRedirectTo('/auth/a/show'); // User should be logged out $this->assertNull(auth('session')->id());