From e922392cb1c66bbd6264420ee062013045cd63b5 Mon Sep 17 00:00:00 2001 From: irbidnet internal lab Date: Sun, 20 Aug 2023 21:35:06 +0300 Subject: [PATCH 1/3] feat: redirect after login to entrance url --- src/Config/Auth.php | 3 ++- src/Filters/SessionAuth.php | 5 +++++ tests/Authentication/Filters/SessionFilterTest.php | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Config/Auth.php b/src/Config/Auth.php index 1c7d57902..792a8ba83 100644 --- a/src/Config/Auth.php +++ b/src/Config/Auth.php @@ -409,7 +409,8 @@ class Auth extends BaseConfig */ public function loginRedirect(): string { - $url = setting('Auth.redirects')['login']; + $session = session(); + $url = $session->getTempdata('beforeLoginUrl') ?? setting('Auth.redirects')['login']; return $this->getUrl($url); } diff --git a/src/Filters/SessionAuth.php b/src/Filters/SessionAuth.php index d95f89c07..6a8a0d8fe 100644 --- a/src/Filters/SessionAuth.php +++ b/src/Filters/SessionAuth.php @@ -75,6 +75,11 @@ public function before(RequestInterface $request, $arguments = null) ->with('error', $authenticator->getPendingMessage()); } + if (! url_is('login')) { + $session = session(); + $session->setTempdata('beforeLoginUrl', current_url(), 300); + } + return redirect()->route('login'); } diff --git a/tests/Authentication/Filters/SessionFilterTest.php b/tests/Authentication/Filters/SessionFilterTest.php index 759a88535..31b2b007c 100644 --- a/tests/Authentication/Filters/SessionFilterTest.php +++ b/tests/Authentication/Filters/SessionFilterTest.php @@ -83,4 +83,12 @@ public function testBlocksInactiveUsers(): void setting('Auth.actions', ['register' => null]); } + + public function testStoreRedirectsToEntraceUrlIntoSession(): void + { + $result = $this->call('get', 'protected-route'); + $result->assertRedirectTo('/login'); + $this->assertNotEmpty($_SESSION['beforeLoginUrl']); + $this->assertSame(site_url('protected-route'), $_SESSION['beforeLoginUrl']); + } } From 292cb3cedbbd6b14c282170a91f7b03b1c8cf654 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Mon, 21 Aug 2023 04:09:42 +0300 Subject: [PATCH 2/3] Update tests/Authentication/Filters/SessionFilterTest.php Co-authored-by: kenjis --- tests/Authentication/Filters/SessionFilterTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/Authentication/Filters/SessionFilterTest.php b/tests/Authentication/Filters/SessionFilterTest.php index 31b2b007c..be66fd2d5 100644 --- a/tests/Authentication/Filters/SessionFilterTest.php +++ b/tests/Authentication/Filters/SessionFilterTest.php @@ -87,8 +87,11 @@ public function testBlocksInactiveUsers(): void public function testStoreRedirectsToEntraceUrlIntoSession(): void { $result = $this->call('get', 'protected-route'); + $result->assertRedirectTo('/login'); - $this->assertNotEmpty($_SESSION['beforeLoginUrl']); - $this->assertSame(site_url('protected-route'), $_SESSION['beforeLoginUrl']); + + $session = session(); + $this->assertNotEmpty($session->get('beforeLogginUrl')); + $this->assertSame(site_url('protected-route'), $session->get('beforeLogginUrl')); } } From 098ac9bfedceee0c043d0dd095d742a0723ded6d Mon Sep 17 00:00:00 2001 From: irbidnet internal lab Date: Mon, 21 Aug 2023 04:52:42 +0300 Subject: [PATCH 3/3] fix session name beforeLoginUrl --- tests/Authentication/Filters/SessionFilterTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Authentication/Filters/SessionFilterTest.php b/tests/Authentication/Filters/SessionFilterTest.php index be66fd2d5..1b379ccc3 100644 --- a/tests/Authentication/Filters/SessionFilterTest.php +++ b/tests/Authentication/Filters/SessionFilterTest.php @@ -91,7 +91,7 @@ public function testStoreRedirectsToEntraceUrlIntoSession(): void $result->assertRedirectTo('/login'); $session = session(); - $this->assertNotEmpty($session->get('beforeLogginUrl')); - $this->assertSame(site_url('protected-route'), $session->get('beforeLogginUrl')); + $this->assertNotEmpty($session->get('beforeLoginUrl')); + $this->assertSame(site_url('protected-route'), $session->get('beforeLoginUrl')); } }