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

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,42 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\TwoFactorNextcloudNotification\Service;
use OCA\TwoFactorNextcloudNotification\AppInfo\Application;
use OCA\TwoFactorNextcloudNotification\Db\Token;
use OCP\IRequest;
use OCP\Notification\IManager;
class NotificationManager {
public function __construct(
private IManager $manager,
private IRequest $request,
) {
}
public function clearNotification(Token $token): void {
$notification = $this->manager->createNotification();
$notification->setApp(Application::APP_ID)
->setSubject('login_attempt')
->setObject('2fa_id', (string)$token->getId());
$this->manager->markProcessed($notification);
}
public function newNotification(Token $token): void {
$notification = $this->manager->createNotification();
$notification->setApp(Application::APP_ID)
->setSubject('login_attempt', [
'ip' => $this->request->getRemoteAddress(),
])
->setObject('2fa_id', (string)$token->getId())
->setUser($token->getUserId())
->setDateTime(new \DateTime());
$this->manager->notify($notification);
}
}
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\TwoFactorNextcloudNotification\Service;
use OCA\TwoFactorNextcloudNotification\AppInfo\Application;
use OCA\TwoFactorNextcloudNotification\Event\StateChanged;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IUser;
class StateManager {
public function __construct(
private IEventDispatcher $dispatcher,
private IConfig $config,
) {
}
public function setState(IUser $user, bool $state): void {
$this->config->setUserValue($user->getUID(), Application::APP_ID, 'enabled', $state ? '1' : '0');
$this->dispatcher->dispatchTyped(new StateChanged($user, $state));
}
public function getState(IUser $user): bool {
return $this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled', '0') === '1';
}
}
@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\TwoFactorNextcloudNotification\Service;
use OCA\TwoFactorNextcloudNotification\Db\Token;
use OCA\TwoFactorNextcloudNotification\Db\TokenMapper;
use OCA\TwoFactorNextcloudNotification\Exception\TokenExpireException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
class TokenManager {
public function __construct(
private TokenMapper $mapper,
private NotificationManager $notificationManager,
private ITimeFactory $timeFactory,
) {
}
/**
* @param int $attemptId
* @return Token
* @throws DoesNotExistException
* @throws TokenExpireException
*/
public function getById(int $attemptId): Token {
return $this->validateToken($this->mapper->getById($attemptId));
}
/**
* @param string $token
* @return Token
* @throws DoesNotExistException
* @throws TokenExpireException
*/
public function getByToken(string $token): Token {
return $this->validateToken($this->mapper->getByToken($token));
}
/**
* @param Token $token
*/
public function delete(Token $token): void {
$this->notificationManager->clearNotification($token);
$this->mapper->delete($token);
}
/**
* @param Token $token
* @return Token
*/
public function update(Token $token): Token {
$this->notificationManager->clearNotification($token);
return $this->mapper->update($token);
}
public function cleanupTokens(): void {
$tokens = $this->mapper->getTokensForCleanup();
foreach ($tokens as $token) {
$this->delete($token);
}
}
public function generate(string $userId): Token {
$token = $this->mapper->generate($userId);
$this->notificationManager->newNotification($token);
return $token;
}
/**
* @param Token $token
* @return Token
* @throws TokenExpireException
*/
protected function validateToken(Token $token): Token {
if (($this->timeFactory->getTime() - $token->getTimestamp()) > 60 * 10) {
$this->delete($token);
throw new TokenExpireException('Token expired');
}
return $token;
}
}