Upgrade to 3.3.1

This commit is contained in:
Bastian Allgeier
2019-11-26 11:04:08 +01:00
parent 23c67beafb
commit 3a82406bed
156 changed files with 437 additions and 121 deletions

View File

@@ -67,7 +67,7 @@ class App
protected $routes;
protected $router;
protected $server;
protected $session;
protected $sessionHandler;
protected $site;
protected $system;
protected $urls;
@@ -784,6 +784,7 @@ class App
/**
* Returns the nonce, which is used
* in the panel for inline scripts
* @since 3.3.0
*
* @return string
*/
@@ -1105,8 +1106,18 @@ class App
*/
public function session(array $options = [])
{
$this->session = $this->session ?? new AutoSession($this->root('sessions'), $this->options['session'] ?? []);
return $this->session->get($options);
return $this->sessionHandler()->get($options);
}
/**
* Returns the session handler
*
* @return \Kirby\Session\AutoSession
*/
public function sessionHandler()
{
$this->sessionHandler = $this->sessionHandler ?? new AutoSession($this->root('sessions'), $this->option('session', []));
return $this->sessionHandler;
}
/**

View File

@@ -198,9 +198,9 @@ class Auth
* @param bool $long
* @return \Kirby\Cms\User
*
* @throws PermissionException If the rate limit was exceeded or if any other error occured with debug mode off
* @throws NotFoundException If the email was invalid
* @throws InvalidArgumentException If the password is not valid (via `$user->login()`)
* @throws \Kirby\Exception\PermissionException If the rate limit was exceeded or if any other error occured with debug mode off
* @throws \Kirby\Exception\NotFoundException If the email was invalid
* @throws \Kirby\Exception\InvalidArgumentException If the password is not valid (via `$user->login()`)
*/
public function login(string $email, string $password, bool $long = false)
{
@@ -214,10 +214,22 @@ class Auth
$user = $this->validatePassword($email, $password);
$user->loginPasswordless($options);
return $user;
}
/**
* Sets a user object as the current user in the cache
* @internal
*
* @param \Kirby\Cms\User $user
* @return void
*/
public function setUser(User $user): void
{
// stop impersonating
$this->impersonate = null;
return $this->user = $user;
$this->user = $user;
}
/**
@@ -228,9 +240,9 @@ class Auth
* @param string $password
* @return \Kirby\Cms\User
*
* @throws PermissionException If the rate limit was exceeded or if any other error occured with debug mode off
* @throws NotFoundException If the email was invalid
* @throws InvalidArgumentException If the password is not valid (via `$user->login()`)
* @throws \Kirby\Exception\PermissionException If the rate limit was exceeded or if any other error occured with debug mode off
* @throws \Kirby\Exception\NotFoundException If the email was invalid
* @throws \Kirby\Exception\InvalidArgumentException If the password is not valid (via `$user->login()`)
*/
public function validatePassword(string $email, string $password)
{
@@ -334,20 +346,30 @@ class Auth
/**
* Logout the current user
*
* @return bool
* @return void
*/
public function logout(): bool
public function logout(): void
{
// stop impersonating
// stop impersonating;
// ensures that we log out the actually logged in user
$this->impersonate = null;
// logout the current user if it exists
if ($user = $this->user()) {
$user->logout();
}
}
/**
* Clears the cached user data after logout
* @internal
*
* @return void
*/
public function flush(): void
{
$this->impersonate = null;
$this->user = null;
return true;
}
/**
@@ -415,7 +437,8 @@ class Auth
*
* @param \Kirby\Session\Session|array|null $session
* @return \Kirby\Cms\User
* @throws
*
* @throws \Throwable If an authentication error occured
*/
public function user($session = null)
{

View File

@@ -405,6 +405,7 @@ abstract class ModelWithContent extends Model
* Returns an array of all actions
* that can be performed in the Panel
* This also checks for the lock status
* @since 3.3.0
*
* @param array $unlock An array of options that will be force-unlocked
* @return array

View File

@@ -438,6 +438,7 @@ class Pages extends Collection
/**
* Filter all pages by excluding the given template
* @since 3.3.0
*
* @param string|array $templates
* @return \Kirby\Cms\Pages

View File

@@ -4,6 +4,7 @@ namespace Kirby\Cms;
use Exception;
use Kirby\Data\Data;
use Kirby\Toolkit\Str;
/**
* Wrapper around Kirby's localization files,
@@ -149,6 +150,21 @@ class Translation
}
}
/**
* Returns the PHP locale of the translation
*
* @return string
*/
public function locale(): string
{
$default = $this->code;
if (Str::contains($default, '_') !== true) {
$default .= '_' . strtoupper($this->code);
}
return $this->get('translation.locale', $default);
}
/**
* Returns the human-readable translation name.
*

View File

@@ -5,7 +5,6 @@ namespace Kirby\Cms;
use Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\NotFoundException;
use Kirby\Exception\PermissionException;
use Kirby\Session\Session;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Str;
@@ -408,7 +407,7 @@ class User extends ModelWithContent
* @param \Kirby\Session\Session|array $session Session options or session object to set the user in
* @return bool
*
* @throws PermissionException If the password is not valid
* @throws \Kirby\Exception\PermissionException If the password is not valid
*/
public function login(string $password, $session = null): bool
{
@@ -434,6 +433,7 @@ class User extends ModelWithContent
$session->regenerateToken(); // privilege change
$session->data()->set('user.id', $this->id());
$this->kirby()->auth()->setUser($this);
$kirby->trigger('user.login:after', $this, $session);
}
@@ -451,8 +451,12 @@ class User extends ModelWithContent
$kirby->trigger('user.logout:before', $this, $session);
// remove the user from the session for future requests
$session->data()->remove('user.id');
// clear the cached user object from the app state of the current request
$this->kirby()->auth()->flush();
if ($session->data()->get() === []) {
// session is now empty, we might as well destroy it
$session->destroy();
@@ -872,9 +876,9 @@ class User extends ModelWithContent
* @param string $password
* @return bool
*
* @throws NotFoundException If the user has no password
* @throws InvalidArgumentException If the entered password is not valid
* @throws InvalidArgumentException If the entered password does not match the user password
* @throws \Kirby\Exception\NotFoundException If the user has no password
* @throws \Kirby\Exception\InvalidArgumentException If the entered password is not valid
* @throws \Kirby\Exception\InvalidArgumentException If the entered password does not match the user password
*/
public function validatePassword(string $password = null): bool
{