Update captcha handling and introduce new captcha mechanism
This commit is contained in:
parent
706666af09
commit
38b96db83a
10 changed files with 189 additions and 6 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace Socialbox\Objects\Database;
|
||||
|
||||
use DateTime;
|
||||
use Socialbox\Classes\Configuration;
|
||||
use Socialbox\Enums\Status\CaptchaStatus;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
|
||||
|
@ -55,6 +56,16 @@ class CaptchaRecord implements SerializableInterface
|
|||
return $this->created;
|
||||
}
|
||||
|
||||
public function getExpires(): DateTime
|
||||
{
|
||||
return $this->created->modify(sprintf("+%s seconds", Configuration::getSecurityConfiguration()->getCaptchaTtl()));
|
||||
}
|
||||
|
||||
public function isExpired(): bool
|
||||
{
|
||||
return $this->getExpires() < new DateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
|
53
src/Socialbox/Objects/Standard/ImageCaptcha.php
Normal file
53
src/Socialbox/Objects/Standard/ImageCaptcha.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Objects\Standard;
|
||||
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\Database\CaptchaRecord;
|
||||
|
||||
class ImageCaptcha implements SerializableInterface
|
||||
{
|
||||
private int $expires;
|
||||
private string $image;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->expires = $data['expires'];
|
||||
$this->image = $data['image'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getExpires(): int
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getImage(): string
|
||||
{
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): object
|
||||
{
|
||||
return new self($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'expires' => $this->expires,
|
||||
'image' => $this->image
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue