* @throws InvalidTokenException
* @param IToken $token
*/
- public function updateToken(IToken $token) {
+ public function updateTokenActivity(IToken $token) {
if (!($token instanceof DefaultToken)) {
throw new InvalidTokenException();
}
/** @var DefaultToken $token */
- $token->setLastActivity($this->time->getTime());
-
- $this->mapper->update($token);
+ $now = $this->time->getTime();
+ if ($token->getLastActivity() < ($now - 60)) {
+ // Update token only once per minute
+ $token->setLastActivity($now);
+ $this->mapper->update($token);
+ }
}
/**
*
* @param IToken $token
*/
- public function updateToken(IToken $token);
+ public function updateTokenActivity(IToken $token);
/**
* Get all token of a user
$this->session->set('last_login_check', $now);
}
- // Session is valid, so the token can be refreshed
- $this->updateToken($token);
+ $this->tokenProvider->updateTokenActivity($token);
}
/**
$result = $this->loginWithToken($token->getUID());
if ($result) {
// Login success
- $this->updateToken($token);
+ $this->tokenProvider->updateTokenActivity($token);
return true;
}
}
return false;
}
- /**
- * @param IToken $token
- */
- private function updateToken(IToken $token) {
- // To save unnecessary DB queries, this is only done once a minute
- $lastTokenUpdate = $this->session->get('last_token_update') ? : 0;
- $now = $this->timeFacory->getTime();
- if ($lastTokenUpdate < ($now - 60)) {
- $this->tokenProvider->updateToken($token);
- $this->session->set('last_token_update', $now);
- }
- }
-
/**
* Tries to login the user with auth token header
*
public function testUpdateToken() {
$tk = new DefaultToken();
+ $tk->setLastActivity($this->time - 200);
$this->mapper->expects($this->once())
->method('update')
->with($tk);
- $this->tokenProvider->updateToken($tk);
+ $this->tokenProvider->updateTokenActivity($tk);
$this->assertEquals($this->time, $tk->getLastActivity());
}
+
+ public function testUpdateTokenDebounce() {
+ $tk = new DefaultToken();
+ $tk->setLastActivity($this->time - 30);
+ $this->mapper->expects($this->never())
+ ->method('update')
+ ->with($tk);
+
+ $this->tokenProvider->updateTokenActivity($tk);
+ }
public function testGetTokenByUser() {
$user = $this->getMock('\OCP\IUser');