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
+10 -4
View File
@@ -335,7 +335,13 @@ class Controller
$author = $this->grav['config']->get('site.author.name', '');
$fullname = $user->fullname ?: $user->username;
$reset_link = $this->grav['base_url_absolute'] . $this->grav['config']->get('plugins.login.route_reset') . '/task:login.reset/token' . $param_sep . $token . '/user' . $param_sep . $user->username . '/nonce' . $param_sep . Utils::getNonce('reset-form');
if ($this->grav['language']->getDefault() != $this->grav['language']->getLanguage()) {
$lang = '/'.$this->grav['language']->getLanguage();
} else {
$lang = '';
}
$reset_link = $this->grav['base_url_absolute'] . $lang . $this->grav['config']->get('plugins.login.route_reset') . '/task:login.reset/token' . $param_sep . $token . '/user' . $param_sep . $user->username . '/nonce' . $param_sep . Utils::getNonce('reset-form');
$sitename = $this->grav['config']->get('site.title', 'Website');
@@ -381,7 +387,7 @@ class Controller
if ($good_token === $token) {
if (time() > $expire) {
$messages->add($language->translate('PLUGIN_LOGIN.RESET_LINK_EXPIRED'), 'error');
$this->grav->redirect($this->grav['config']->get('plugins.login.route_forgot', '/'));
$this->grav->redirectLangSafe($this->grav['config']->get('plugins.login.route_forgot', '/'));
return true;
}
@@ -401,7 +407,7 @@ class Controller
}
$messages->add($language->translate('PLUGIN_LOGIN.RESET_INVALID_LINK'), 'error');
$this->grav->redirect($this->grav['config']->get('plugins.login.route_forgot'));
$this->grav->redirectLangSafe($this->grav['config']->get('plugins.login.route_forgot'));
return true;
@@ -412,7 +418,7 @@ class Controller
if (!$user || !$token) {
$messages->add($language->translate('PLUGIN_LOGIN.RESET_INVALID_LINK'), 'error');
$this->grav->redirect($this->grav['config']->get('plugins.login.route_forgot'));
$this->grav->redirectLangSafe($this->grav['config']->get('plugins.login.route_forgot'));
return true;
}
+7 -8
View File
@@ -196,7 +196,7 @@ class Login
}
if ($redirect) {
$this->grav->redirect($redirect, $event->getRedirectCode());
$this->grav->redirectLangSafe($redirect, $event->getRedirectCode());
}
return $user->authenticated && $user->authorized;
@@ -230,7 +230,7 @@ class Login
$username = $this->validateField('username', $data['username']);
$file = CompiledYamlFile::instance($this->grav['locator']->findResource('account://' . $username . YAML_EXT,
$file = CompiledYamlFile::instance($this->grav['locator']->findResource('account://' . mb_strtolower($username) . YAML_EXT,
true, true));
// Create user object and save it
@@ -423,9 +423,6 @@ class Login
$author
]);
$to = $user->email;
$sent = EmailUtils::sendEmail($subject, $content, $to);
if ($sent < 1) {
@@ -452,12 +449,14 @@ class Login
if (!$this->rememberMe) {
/** @var Config $config */
$config = $this->grav['config'];
$cookieName = $config->get('plugins.login.rememberme.name');
$timeout = $config->get('plugins.login.rememberme.timeout');
// Setup storage for RememberMe cookies
$storage = new TokenStorage;
$storage = new TokenStorage('user://data/rememberme', $timeout);
$this->rememberMe = new RememberMe($storage);
$this->rememberMe->setCookieName($config->get('plugins.login.rememberme.name'));
$this->rememberMe->setExpireTime($config->get('plugins.login.rememberme.timeout'));
$this->rememberMe->setCookieName($cookieName);
$this->rememberMe->setExpireTime($timeout);
// Hardening cookies with user-agent and random salt or
// fallback to use system based cache key
@@ -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');
}
}