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
18 changes: 8 additions & 10 deletions src/Illuminate/Auth/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public function user()
// pull the user data on that cookie which serves as a remember cookie on
// the application. Once we have a user we can return it to the caller.
$recaller = $this->getRecaller();

if (is_null($user) && ! is_null($recaller))
{
$user = $this->getUserByRecaller($recaller);
Expand All @@ -167,7 +166,7 @@ public function id()
{
if ($this->loggedOut) return;

$id = $this->session->get($this->getName(), $this->getRecallerId());
$id = $this->session->get($this->getName());

if (is_null($id) && $this->user())
{
Expand Down Expand Up @@ -210,15 +209,14 @@ protected function getRecaller()
/**
* Get the user ID from the recaller cookie.
*
* @return string
* @return int
*/
protected function getRecallerId()
{
if ($this->validRecaller($recaller = $this->getRecaller()))
{
return head(explode('|', $recaller));
}
}
protected function getRecallerId()
{
if ($this->validRecaller($recaller = $this->getRecaller())) {
return (int) head(explode('|', $recaller));
}
}

/**
* Determine if the recaller cookie is in a valid format.
Expand Down
23 changes: 23 additions & 0 deletions tests/Auth/AuthGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,27 @@ public function testUserUsesRememberCookieIfItExists()
$this->assertEquals($user->reveal(), $guard->user());
$this->assertTrue($guard->viaRemember());
}

public function testGetIdWhenRememberCookieExistsWillReturnIntegerIdFromCookieValue()
{
$request = Request::create('/', 'GET', [], [
'remember_82e5d2c56bdd0811318f0cf078b78bfc' => '123|recaller'
]);
$user = $this->prophesize(UserInterface::class);
$user->getAuthIdentifier()->willReturn(123);

$this->userProvider
->retrieveByToken(123, 'recaller')
->willReturn($user->reveal());

$guard = new Guard(
$this->userProvider->reveal(),
$this->session->reveal(),
$request
);

$this->assertNotNull($guard->id());
$this->assertIsInt($guard->id());
$this->assertSame(123, $guard->id());
}
}