basic notify_push usage with session handling (rebased)
Signed-off-by: chandi Langecker <git@chandi.it>
This commit is contained in:
@@ -44,6 +44,7 @@ class Board extends RelationalEntity {
|
||||
protected $users = [];
|
||||
protected $shared;
|
||||
protected $stacks = [];
|
||||
protected $activeSessions = [];
|
||||
protected $deletedAt = 0;
|
||||
protected $lastModified = 0;
|
||||
|
||||
@@ -59,6 +60,7 @@ class Board extends RelationalEntity {
|
||||
$this->addRelation('acl');
|
||||
$this->addRelation('shared');
|
||||
$this->addRelation('users');
|
||||
$this->addRelation('activeSessions');
|
||||
$this->addRelation('permissions');
|
||||
$this->addRelation('stacks');
|
||||
$this->addRelation('settings');
|
||||
|
||||
48
lib/Db/Session.php
Normal file
48
lib/Db/Session.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2022, chandi Langecker (git@chandi.it)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class Session extends Entity implements \JsonSerializable {
|
||||
public $id;
|
||||
protected $userId;
|
||||
protected $token;
|
||||
protected $lastContact;
|
||||
protected $boardId;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id', 'integer');
|
||||
$this->addType('boardId', 'integer');
|
||||
$this->addType('lastContact', 'integer');
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'userId' => $this->userId,
|
||||
'token' => $this->token,
|
||||
'lastContact' => $this->lastContact,
|
||||
'boardId' => $this->boardId,
|
||||
];
|
||||
}
|
||||
}
|
||||
62
lib/Db/SessionMapper.php
Normal file
62
lib/Db/SessionMapper.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2022, chandi Langecker (git@chandi.it)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use OCA\Deck\Service\SessionService;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\QBMapper;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class SessionMapper extends QBMapper {
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'deck_sessions', Session::class);
|
||||
}
|
||||
|
||||
public function find(int $boardId, string $userId, string $token): Session {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$result = $qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where($qb->expr()->eq('board_id', $qb->createNamedParameter($boardId)))
|
||||
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
|
||||
->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
|
||||
->andWhere($qb->expr()->gt('last_contact', $qb->createNamedParameter(time() - SessionService::SESSION_VALID_TIME)))
|
||||
->executeQuery();
|
||||
|
||||
$data = $result->fetch();
|
||||
$result->closeCursor();
|
||||
if ($data === false) {
|
||||
throw new DoesNotExistException('Session is invalid');
|
||||
}
|
||||
return Session::fromRow($data);
|
||||
}
|
||||
|
||||
public function findAllActive($boardId) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('id', 'board_id', 'last_contact', 'user_id')
|
||||
->from($this->getTableName())
|
||||
->where($qb->expr()->eq('board_id', $qb->createNamedParameter($boardId)))
|
||||
->andWhere($qb->expr()->gt('last_contact', $qb->createNamedParameter(time() - SessionService::SESSION_VALID_TIME)))
|
||||
->executeQuery();
|
||||
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user