Compare commits

...

2 Commits

Author SHA1 Message Date
fd286c9cff
Merge pull request 'check session validity by DatabaseSessionHandler' (#16) from feature/sessions-should-expire into master
All checks were successful
soko-web/pipeline/head This commit looks good
Reviewed-on: #16
2023-05-02 12:55:47 +02:00
72fc78220f
check session validity by DatabaseSessionHandler
All checks were successful
soko-web/pipeline/pr-master This commit looks good
2023-05-02 12:37:31 +02:00

View File

@ -13,14 +13,17 @@ class DatabaseSessionHandler implements ISessionHandler
private string $table;
private DateTime $shouldBeNewerThan;
private bool $exists = false;
private bool $written = false;
public function __construct(IConnection $dbConnection, string $table)
public function __construct(IConnection $dbConnection, string $table, DateTime $shouldBeNewerThan)
{
$this->dbConnection = $dbConnection;
$this->table = $table;
$this->shouldBeNewerThan = $shouldBeNewerThan;
}
public function open($savePath, $sessionName): bool
@ -36,17 +39,20 @@ class DatabaseSessionHandler implements ISessionHandler
public function read($id): string
{
$select = new Select($this->dbConnection, $this->table);
$select->columns(['data']);
$select->columns(['data', 'updated']);
$select->whereId(substr($id, 0, 32));
$result = $select->execute()->fetch(IResultSet::FETCH_ASSOC);
if ($result === null) {
return '';
}
$this->exists = true;
if (new DateTime($result['updated']) < $this->shouldBeNewerThan) {
return '';
}
return $result['data'];
}