Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Filters/AbstractAuthFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function before(RequestInterface $request, $arguments = null)
}

if (! auth()->loggedIn()) {
// Set the entrance url to redirect a user after successful login
if (! url_is('login')) {
$session = session();
$session->setTempdata('beforeLoginUrl', current_url(), 300);
Comment on lines +35 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just came up with this code, but it is a copy and paste.
Since it is the same knowledge (save the URL for 300 seconds in the session), it might be better to put it together in a method if possible.

But there doesn't seem to be an appropriate class to put it in now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm currently merge this. Maybe we can refactor later.

}

return redirect()->route('login');
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Authentication/Filters/GroupFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public function testFilterNotAuthorized(): void
$result->assertSee('Open');
}

public function testFilterNotAuthorizedStoresRedirectToEntranceUrlIntoSession(): void
{
$result = $this->call('get', 'protected-route');

$result->assertRedirectTo('/login');

$this->assertNotEmpty(session()->getTempdata('beforeLoginUrl'));
$this->assertSame(site_url('protected-route'), session()->getTempdata('beforeLoginUrl'));
}

public function testFilterSuccess(): void
{
/** @var User $user */
Expand Down
10 changes: 10 additions & 0 deletions tests/Authentication/Filters/PermissionFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public function testFilterNotAuthorized(): void
$result->assertSee('Open');
}

public function testFilterNotAuthorizedStoresRedirectToEntranceUrlIntoSession(): void
{
$result = $this->call('get', 'protected-route');

$result->assertRedirectTo('/login');

$this->assertNotEmpty(session()->getTempdata('beforeLoginUrl'));
$this->assertSame(site_url('protected-route'), session()->getTempdata('beforeLoginUrl'));
}

public function testFilterSuccess(): void
{
/** @var User $user */
Expand Down