public function TokenManager::validateToken in Persistent Login 8
Check the database for the provided token.
If valid, a new token is returned with the uid set to the associated user, otherwise a new invalid token is returned.
Parameters
\Drupal\persistent_login\PersistentToken $token: The token to validate.
Return value
\Drupal\persistent_login\PersistentToken A validated token.
File
- src/
TokenManager.php, line 96
Class
- TokenManager
- Class TokenManager.
Namespace
Drupal\persistent_loginCode
public function validateToken(PersistentToken $token) {
$selectResult = $this->connection
->select('persistent_login', 'pl')
->fields('pl', [
'uid',
'created',
'refreshed',
'expires',
])
->condition('expires', $this->time
->getRequestTime(), '>')
->condition('series', $token
->getSeries())
->condition('instance', $token
->getInstance())
->execute();
if ($tokenData = $selectResult
->fetchObject()) {
return $token
->setUid($tokenData->uid)
->setCreated(new DateTime('@' . $tokenData->created))
->setRefreshed(new DateTime('@' . $tokenData->refreshed))
->setExpiry(new DateTime('@' . $tokenData->expires));
}
else {
return $token
->setInvalid();
}
}