Scrollreveal+cat+datenews

This commit is contained in:
2019-01-07 11:43:39 +01:00
parent e4cac3d01e
commit 762a1ad170
3158 changed files with 140699 additions and 73915 deletions
@@ -2,35 +2,28 @@
/**
* @package Grav\Plugin\Login
*
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
* @copyright Copyright (C) 2014 - 2018 RocketTheme, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Plugin\Login\RememberMe;
use Grav\Common\Cache;
use Grav\Common\File\CompiledYamlFile;
use Grav\Common\Filesystem\Folder;
use Grav\Common\Grav;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\FilesystemCache;
use Birke\Rememberme\Storage\StorageInterface;
/**
* Storage wrapper for Doctrine cache
* Token Storage wrapper
*
* Used for storing the credential/token/persistentToken triplets.
*
* @author Sommerregen <sommerregen@benjamin-regler.de>
*/
class TokenStorage implements StorageInterface
{
/**
* @var CacheProvider
*/
protected $driver;
/** @var string */
protected $path;
/**
* @var string
*/
protected $cache_dir;
/** @var int */
protected $timeout;
/**
* Constructor
@@ -38,28 +31,16 @@ class TokenStorage implements StorageInterface
* @param string $path Path to storage directory
* @throws \InvalidArgumentException
*/
public function __construct($path = 'cache://rememberme')
public function __construct($path = 'user://data/rememberme', $timeout = 604800)
{
/** @var Cache $cache */
$cache = Grav::instance()['cache'];
$this->cache_dir = Grav::instance()['locator']->findResource($path, true, true);
// Setup cache
$this->driver = $cache->getCacheDriver();
if ($this->driver instanceof FilesystemCache) {
$this->driver = new FilesystemCache($this->cache_dir);
}
// Set the cache namespace to our unique key
$this->driver->setNamespace($cache->getKey());
$this->path = Grav::instance()['locator']->findResource($path, true, true);
$this->timeout = $timeout;
}
/**
* Return Tri-state value constant
*
* @param mixed $credential Unique credential (user id,
* email address, user name)
* @param mixed $credential Unique credential (user id, email address, user name)
* @param string $token One-Time Token
* @param string $persistentToken Persistent Token
*
@@ -67,64 +48,47 @@ class TokenStorage implements StorageInterface
*/
public function findTriplet($credential, $token, $persistentToken)
{
// Hash the tokens, because they can contain a salt and can be accessed in the file system
$persistentToken = sha1($persistentToken);
$token = sha1($token);
// Hash the tokens, because they can contain a salt and can be
// accessed in the file system
$persistentToken = sha1(trim($persistentToken));
$token = sha1(trim($token));
$file = $this->getFile($credential);
$tokens = (array)$file->content();
$id = $this->getId($credential);
if (!$this->driver->contains($id)) {
if (!isset($tokens[$persistentToken]) || $tokens[$persistentToken] < time() + $this->timeout) {
return self::TRIPLET_NOT_FOUND;
}
list($expire, $tokens) = $this->driver->fetch($id);
if (isset($tokens[$persistentToken]) && $tokens[$persistentToken] === $token) {
return self::TRIPLET_FOUND;
$stored = key($tokens[$persistentToken]);
if ($stored !== $token) {
return self::TRIPLET_INVALID;
}
return self::TRIPLET_INVALID;
return self::TRIPLET_FOUND;
}
/**
* Store the new token for the credential and the persistent token.
* Create a new storage entry, if the combination of credential and
* persistent token does not exist.
* Store the new token for the credential and the persistent token. Create a new storage entry, if the combination
* of credential and persistent token does not exist.
*
* @param mixed $credential
* @param string $token
* @param string $persistentToken
* @param int $expire Timestamp when this triplet
* will expire (0 = no expiry)
* @param int $expire Timestamp when this triplet will expire (0 = no expiry)
*/
public function storeTriplet($credential, $token, $persistentToken, $expire = null)
{
// Hash the tokens, because they can contain a salt and can be
// accessed in the file system
$persistentToken = sha1(trim($persistentToken));
$token = sha1(trim($token));
// Hash the tokens, because they can contain a salt and can be accessed in the file system
$persistentToken = sha1($persistentToken);
$token = sha1($token);
$e = null;
$tokens = [];
$id = $this->getId($credential);
if ($this->driver->contains($id)) {
list($e, $tokens) = $this->driver->fetch($id);
}
$file = $this->getFile($credential);
$tokens = (array)$file->content();
// Get cache lifetime for tokens
if ($expire === null && $e === null) {
/** @var Cache $cache */
$cache = Grav::instance()['cache'];
$expire = $cache->getLifetime();
} elseif ($expire === null) {
$expire = $e;
}
// Update token
$tokens[$persistentToken] = [$token => time()];
// Update tokens
$tokens[$persistentToken] = $token;
$this->driver->save($id, [$expire, $tokens], $expire);
return $this;
$file->save($tokens);
}
/**
@@ -137,7 +101,6 @@ class TokenStorage implements StorageInterface
*/
public function replaceTriplet($credential, $token, $persistentToken, $expire = null)
{
$this->cleanTriplet($credential, $persistentToken);
$this->storeTriplet($credential, $token, $persistentToken, $expire);
}
@@ -149,16 +112,25 @@ class TokenStorage implements StorageInterface
*/
public function cleanTriplet($credential, $persistentToken)
{
// Hash the tokens, because they can contain a salt and can be
// accessed in the file system
$persistentToken = sha1(trim($persistentToken));
// Hash the tokens, because they can contain a salt and can be accessed in the file system
$persistentToken = sha1($persistentToken);
// Delete token from storage
$id = $this->getId($credential);
if ($this->driver->contains($id)) {
list($expire, $tokens) = $this->driver->fetch($id);
$file = $this->getFile($credential);
if (!$file->exists()) {
return;
}
$tokens = (array)$file->content();
if (isset($tokens[$persistentToken])) {
// Delete token from storage
unset($tokens[$persistentToken]);
$this->driver->save($id, [$expire, $tokens], $expire);
if ($tokens) {
$file->save($tokens);
} else {
$file->delete();
}
}
}
@@ -170,8 +142,10 @@ class TokenStorage implements StorageInterface
*/
public function cleanAllTriplets($credential)
{
$id = $this->getId($credential);
$this->driver->delete($id);
$file = $this->getFile($credential);
if ($file->exists()) {
$file->delete();
}
}
/**
@@ -179,20 +153,17 @@ class TokenStorage implements StorageInterface
*/
public function clearCache()
{
$this->driver->flushAll();
if (is_dir($this->path)) {
Folder::delete($this->path, false);
}
}
/**
* Get the cache id
*
* @param string $key A key to compute the cache id for
* @return string The cache id
* @param string $credential
* @return CompiledYamlFile
*/
protected function getId($key)
protected function getFile($credential)
{
/** @var Cache $cache */
$cache = Grav::instance()['cache'];
return 'login' . md5(trim($key) . $cache->getKey());
return CompiledYamlFile::instance($this->path . '/' . sha1($credential) . '.yaml');
}
}