Skip to content

Commit

Permalink
Added new 'Auth::viaRemember method to determine if user was authed v…
Browse files Browse the repository at this point in the history
…ia 'remember me' cookie.
  • Loading branch information
taylorotwell committed Oct 28, 2013
1 parent 5483042 commit 2184ad4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Illuminate/Auth/Guard.php
Expand Up @@ -16,6 +16,13 @@ class Guard {
*/
protected $user;

/**
* Indicates if the user was authenticated via a recaller cookie.
*
* @var bool
*/
protected $viaRemember = false;

/**
* The user provider implementation.
*
Expand Down Expand Up @@ -131,6 +138,8 @@ public function user()
if (is_null($user) and ! is_null($recaller))
{
$user = $this->provider->retrieveByID($recaller);

$this->viaRemember = ! is_null($user);
}

return $this->user = $user;
Expand Down Expand Up @@ -578,4 +587,14 @@ public function getRecallerName()
return 'remember_'.md5(get_class($this));
}

/**
* Determine if the user was authenticated via "remember me" cookie.
*
* @return bool
*/
public function viaRemember()
{
return $this->viaRemember;
}

}
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/changes.json
Expand Up @@ -30,7 +30,8 @@
{"message": "Added 'whereNotBetween' support to the query builder.", "backport": null},
{"message": "Added App::middleware method to inject middlewares onto Stack.", "backport": null},
{"message": "Deprecate 'close' application hooks, Stack middlewares should be used instead.", "backport": null},
{"message": "A new packages directory within `lang` can now override package language files.", "backport": null}
{"message": "A new packages directory within `lang` can now override package language files.", "backport": null},
{"message": "Added new 'Auth::viaRemember method to determine if user was authed via 'remember me' cookie.", "backport": null}
],
"4.0.x": [
{"message": "Added implode method to query builder and Collection class.", "backport": null},
Expand Down
1 change: 1 addition & 0 deletions tests/Auth/AuthGuardTest.php
Expand Up @@ -226,6 +226,7 @@ public function testUserUsesRememberCookieIfItExists()
$user = m::mock('Illuminate\Auth\UserInterface');
$guard->getProvider()->shouldReceive('retrieveById')->once()->with('recaller')->andReturn($user);
$this->assertEquals($user, $guard->user());
$this->assertTrue($guard->viaRemember());
}


Expand Down

0 comments on commit 2184ad4

Please sign in to comment.