No need to set a remember cookie if only logging in for session

This commit is contained in:
Toby Zerner 2017-10-07 17:51:30 +10:30
parent 659b25bbfd
commit 9a8433d02c
2 changed files with 7 additions and 8 deletions

View File

@ -81,7 +81,9 @@ class LogInController implements ControllerInterface
event(new UserLoggedIn($this->users->findOrFail($data->userId), $token)); event(new UserLoggedIn($this->users->findOrFail($data->userId), $token));
$response = $this->rememberer->remember($response, $token, ! array_get($body, 'remember')); if (array_get($body, 'remember')) {
$response = $this->rememberer->remember($response, $token);
}
} }
return $response; return $response;

View File

@ -24,7 +24,6 @@ class Rememberer
protected $cookie; protected $cookie;
/** /**
* Rememberer constructor.
* @param CookieFactory $cookie * @param CookieFactory $cookie
*/ */
public function __construct(CookieFactory $cookie) public function __construct(CookieFactory $cookie)
@ -32,18 +31,16 @@ class Rememberer
$this->cookie = $cookie; $this->cookie = $cookie;
} }
public function remember(ResponseInterface $response, AccessToken $token, $session = false) public function remember(ResponseInterface $response, AccessToken $token)
{ {
$lifetime = null; $lifetime = null;
if (! $session) { $token->lifetime = 5 * 365 * 24 * 60 * 60; // 5 years
$token->lifetime = $lifetime = 5 * 365 * 24 * 60 * 60; // 5 years $token->save();
$token->save();
}
return FigResponseCookies::set( return FigResponseCookies::set(
$response, $response,
$this->cookie->make(self::COOKIE_NAME, $token->id, $lifetime) $this->cookie->make(self::COOKIE_NAME, $token->id, $token->lifetime)
); );
} }