downgrade to kirby v3
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace Kirby\Cms\Auth;
|
||||
|
||||
use Kirby\Cms\App;
|
||||
use Kirby\Cms\User;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Toolkit\Properties;
|
||||
|
||||
@@ -20,32 +19,44 @@ use Kirby\Toolkit\Properties;
|
||||
*/
|
||||
class Status
|
||||
{
|
||||
use Properties;
|
||||
|
||||
/**
|
||||
* Type of the active challenge
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected string|null $challenge = null;
|
||||
protected $challenge = null;
|
||||
|
||||
/**
|
||||
* Challenge type to use as a fallback
|
||||
* when $challenge is `null`
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected string|null $challengeFallback = null;
|
||||
protected $challengeFallback = null;
|
||||
|
||||
/**
|
||||
* Email address of the current/pending user
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected string|null $email;
|
||||
protected $email = null;
|
||||
|
||||
/**
|
||||
* Kirby instance for user lookup
|
||||
*
|
||||
* @var \Kirby\Cms\App
|
||||
*/
|
||||
protected App $kirby;
|
||||
protected $kirby;
|
||||
|
||||
/**
|
||||
* Authentication status:
|
||||
* `active|impersonated|pending|inactive`
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected string $status;
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
@@ -54,24 +65,13 @@ class Status
|
||||
*/
|
||||
public function __construct(array $props)
|
||||
{
|
||||
if (in_array($props['status'], ['active', 'impersonated', 'pending', 'inactive']) !== true) {
|
||||
throw new InvalidArgumentException([
|
||||
'data' => [
|
||||
'argument' => '$props[\'status\']',
|
||||
'method' => 'Status::__construct'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
$this->kirby = $props['kirby'];
|
||||
$this->challenge = $props['challenge'] ?? null;
|
||||
$this->challengeFallback = $props['challengeFallback'] ?? null;
|
||||
$this->email = $props['email'] ?? null;
|
||||
$this->status = $props['status'];
|
||||
$this->setProperties($props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authentication status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
@@ -84,8 +84,9 @@ class Status
|
||||
* @param bool $automaticFallback If set to `false`, no faked challenge is returned;
|
||||
* WARNING: never send the resulting `null` value to the
|
||||
* user to avoid leaking whether the pending user exists
|
||||
* @return string|null
|
||||
*/
|
||||
public function challenge(bool $automaticFallback = true): string|null
|
||||
public function challenge(bool $automaticFallback = true): ?string
|
||||
{
|
||||
// never return a challenge type if the status doesn't match
|
||||
if ($this->status() !== 'pending') {
|
||||
@@ -94,30 +95,17 @@ class Status
|
||||
|
||||
if ($automaticFallback === false) {
|
||||
return $this->challenge;
|
||||
} else {
|
||||
return $this->challenge ?? $this->challengeFallback;
|
||||
}
|
||||
|
||||
return $this->challenge ?? $this->challengeFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance while
|
||||
* merging initial and new properties
|
||||
*/
|
||||
public function clone(array $props = []): static
|
||||
{
|
||||
return new static(array_replace_recursive([
|
||||
'kirby' => $this->kirby,
|
||||
'challenge' => $this->challenge,
|
||||
'challengeFallback' => $this->challengeFallback,
|
||||
'email' => $this->email,
|
||||
'status' => $this->status,
|
||||
], $props));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the email address of the current/pending user
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function email(): string|null
|
||||
public function email(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
@@ -134,6 +122,8 @@ class Status
|
||||
|
||||
/**
|
||||
* Returns an array with all public status data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
@@ -146,8 +136,10 @@ class Status
|
||||
|
||||
/**
|
||||
* Returns the currently logged in user
|
||||
*
|
||||
* @return \Kirby\Cms\User
|
||||
*/
|
||||
public function user(): User|null
|
||||
public function user()
|
||||
{
|
||||
// for security, only return the user if they are
|
||||
// already logged in
|
||||
@@ -157,4 +149,71 @@ class Status
|
||||
|
||||
return $this->kirby->user($this->email());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the active challenge
|
||||
*
|
||||
* @param string|null $challenge
|
||||
* @return $this
|
||||
*/
|
||||
protected function setChallenge(?string $challenge = null)
|
||||
{
|
||||
$this->challenge = $challenge;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the challenge type to use as
|
||||
* a fallback when $challenge is `null`
|
||||
*
|
||||
* @param string|null $challengeFallback
|
||||
* @return $this
|
||||
*/
|
||||
protected function setChallengeFallback(?string $challengeFallback = null)
|
||||
{
|
||||
$this->challengeFallback = $challengeFallback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the email address of the current/pending user
|
||||
*
|
||||
* @param string|null $email
|
||||
* @return $this
|
||||
*/
|
||||
protected function setEmail(?string $email = null)
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Kirby instance for user lookup
|
||||
*
|
||||
* @param \Kirby\Cms\App $kirby
|
||||
* @return $this
|
||||
*/
|
||||
protected function setKirby(App $kirby)
|
||||
{
|
||||
$this->kirby = $kirby;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the authentication status
|
||||
*
|
||||
* @param string $status `active|impersonated|pending|inactive`
|
||||
* @return $this
|
||||
*/
|
||||
protected function setStatus(string $status)
|
||||
{
|
||||
if (in_array($status, ['active', 'impersonated', 'pending', 'inactive']) !== true) {
|
||||
throw new InvalidArgumentException([
|
||||
'data' => ['argument' => '$props[\'status\']', 'method' => 'Status::__construct']
|
||||
]);
|
||||
}
|
||||
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user