Обновление клиента

This commit is contained in:
root
2026-03-05 13:40:40 +00:00
parent 34bcd34979
commit b8905de237
4147 changed files with 748711 additions and 7 deletions
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\TwoFactorNextcloudNotification\Db;
use OCP\AppFramework\Db\Entity;
use OCP\DB\Types;
/**
* @method string getUserId()
* @method void setUserId(string $userId)
* @method string getToken()
* @method void setToken(string $token)
* @method int getStatus()
* @method void setStatus(int $status)
* @method int getTimestamp()
* @method void setTimestamp(int $timestamp)
*/
class Token extends Entity {
public const PENDING = 0;
public const ACCEPTED = 1;
public const REJECTED = 2;
/** @var string */
protected $userId;
/** @var string */
protected $token;
/** @var int */
protected $status;
/** @var int */
protected $timestamp;
public function __construct() {
$this->addType('userId', Types::STRING);
$this->addType('token', Types::STRING);
$this->addType('status', Types::INTEGER);
$this->addType('timestamp', Types::INTEGER);
}
}
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\TwoFactorNextcloudNotification\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
use OCP\Security\ISecureRandom;
/**
* @template-extends QBMapper<Token>
*/
class TokenMapper extends QBMapper {
public function __construct(
IDBConnection $db,
private ITimeFactory $timeFactory,
private ISecureRandom $random,
) {
parent::__construct($db, 'twofactor_tnn_tokens', Token::class);
}
/**
* @param string $token
* @return Token
* @throws DoesNotExistException
*/
public function getByToken(string $token): Token {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('token', $qb->createNamedParameter($token))
);
return $this->findEntity($qb);
}
/**
* @param int $id
* @return Token
* @throws DoesNotExistException
*/
public function getById(int $id): Token {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('id', $qb->createNamedParameter($id))
);
return $this->findEntity($qb);
}
public function generate(string $userId): Token {
$token = new Token();
$token->setStatus(Token::PENDING);
$token->setUserId($userId);
$token->setTimestamp($this->timeFactory->getTime());
$token->setToken($this->random->generate(40, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER));
/** @var Token $token */
$token = $this->insert($token);
return $token;
}
public function getTokensForCleanup(): array {
// Clear all tokens older than 10 minutes
$time = $this->timeFactory->getTime() - (60 * 10);
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->lt('timestamp', $qb->createNamedParameter($time)));
return $this->findEntities($qb);
}
}