Skip to content

Commit

Permalink
Merge pull request #8 from sandstorm/feature/make-token-consumption-c…
Browse files Browse the repository at this point in the history
…onfigurable

FEATURE: Make consumption of tokens configurable in preset
  • Loading branch information
kdambekalns committed Jan 20, 2018
2 parents 874c0f4 + 2b44ec9 commit e5154d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
21 changes: 20 additions & 1 deletion Classes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,32 @@ public function validateTokenHash($tokenHash)
return NULL;
}

$this->tokenCache->remove($tokenHash);
$preset = $this->getPreset($tokenData['presetName']);
if (! (isset($preset['preserveToken']) && $preset['preserveToken'])) {
$this->tokenCache->remove($tokenHash);
}

$this->logger->log(sprintf('Validated token hash %s for identifier %s', $tokenHash, $tokenData['identifier']), LOG_INFO);

return new Token($tokenHash, $tokenData['identifier'], $this->getPreset($tokenData['presetName']), $tokenData['meta']);
}

/**
* Removes the given token from the token cache.
*
* This is only necessary if the 'preserveToken' parameter of the token's preset is true.
* Otherwise tokens are deleted automatically.
*
* @param Token $token
* @return void
*/
public function invalidateToken(Token $token)
{
$this->tokenCache->remove($token->getHash());

$this->logger->log(sprintf('Deleted token %s.', $token->getIdentifier()), LOG_INFO);
}

/**
* For the given $token an activation link is returned.
*
Expand Down
2 changes: 2 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Flownative:
tokenLength: 32
# how long a token should be valid after generation, in seconds
lifetime: 86400
# if set to true, tokens are not removed from cache automatically when the activation link is called
preserveToken: true
# configuration for building an activation link for a token
activation:
# if uri is given as a string, it is used as given.
Expand Down
2 changes: 1 addition & 1 deletion Documentation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ following `default` preset is used:

.. literalinclude:: ../Configuration/Settings.yaml
:language: yaml
:lines: 1-37
:lines: 1-39
:emphasize-lines: 5-

To adjust this default preset, override as usual:
Expand Down

0 comments on commit e5154d4

Please sign in to comment.