From 27b4323bedd718b58e2d1ed0600439fceec5a923 Mon Sep 17 00:00:00 2001 From: irbidnet internal lab Date: Tue, 15 Aug 2023 19:05:45 +0300 Subject: [PATCH 1/3] Redirect after login to entrance url #722 --- src/Config/Auth.php | 3 ++- src/Filters/SessionAuth.php | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Config/Auth.php b/src/Config/Auth.php index 1c7d57902..ee06c2c65 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('beforeLogginUrl') ?? setting('Auth.redirects')['login']; return $this->getUrl($url); } diff --git a/src/Filters/SessionAuth.php b/src/Filters/SessionAuth.php index d95f89c07..afd0b3cba 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('beforeLogginUrl', current_url(), 300); + } + return redirect()->route('login'); } From 03f3a2c6c3bb3b4a26efb2f7c628615a8e673dc3 Mon Sep 17 00:00:00 2001 From: irbidnet internal lab Date: Thu, 17 Aug 2023 15:12:45 +0300 Subject: [PATCH 2/3] feat: redirect after login to entrance url --- tests/Authentication/Filters/SessionFilterTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Authentication/Filters/SessionFilterTest.php b/tests/Authentication/Filters/SessionFilterTest.php index 759a88535..be19b16ff 100644 --- a/tests/Authentication/Filters/SessionFilterTest.php +++ b/tests/Authentication/Filters/SessionFilterTest.php @@ -83,4 +83,11 @@ 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['beforeLogginUrl']); + } } From 8bf8c4f5df60e78353cfa4d65cd850d0b8fe7fd9 Mon Sep 17 00:00:00 2001 From: irbidnet internal lab Date: Thu, 17 Aug 2023 15:48:19 +0300 Subject: [PATCH 3/3] feat: redirect after login to entrance url --- tests/Authentication/Filters/SessionFilterTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Authentication/Filters/SessionFilterTest.php b/tests/Authentication/Filters/SessionFilterTest.php index be19b16ff..41d44621b 100644 --- a/tests/Authentication/Filters/SessionFilterTest.php +++ b/tests/Authentication/Filters/SessionFilterTest.php @@ -89,5 +89,6 @@ public function testStoreRedirectsToEntraceUrlIntoSession(): void $result = $this->call('get', 'protected-route'); $result->assertRedirectTo('/login'); $this->assertNotEmpty($_SESSION['beforeLogginUrl']); + $this->assertSame(site_url('protected-route'), $_SESSION['beforeLogginUrl']); } }