diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-09-29 21:03:28 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-10-01 15:35:25 +0200 |
commit | c55731426240c0debd3a9bad3cb5e32b6f7e76a8 (patch) | |
tree | 895addc0bdda121221d5b1d90ebe894a0622a497 /apps/twofactor_backupcodes/lib | |
parent | 956fe1b86769c1a8a380a61ba72441f0e334e36a (diff) | |
download | nextcloud-server-c55731426240c0debd3a9bad3cb5e32b6f7e76a8.tar.gz nextcloud-server-c55731426240c0debd3a9bad3cb5e32b6f7e76a8.zip |
Clear notification to generate backup code once codes are generated
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/twofactor_backupcodes/lib')
-rw-r--r-- | apps/twofactor_backupcodes/lib/AppInfo/Application.php | 2 | ||||
-rw-r--r-- | apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php | 51 |
2 files changed, 53 insertions, 0 deletions
diff --git a/apps/twofactor_backupcodes/lib/AppInfo/Application.php b/apps/twofactor_backupcodes/lib/AppInfo/Application.php index 1af114a2791..f5d0139dbd9 100644 --- a/apps/twofactor_backupcodes/lib/AppInfo/Application.php +++ b/apps/twofactor_backupcodes/lib/AppInfo/Application.php @@ -28,6 +28,7 @@ namespace OCA\TwoFactorBackupCodes\AppInfo; use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper; use OCA\TwoFactorBackupCodes\Event\CodesGenerated; use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher; +use OCA\TwoFactorBackupCodes\Listener\ClearNotifications; use OCA\TwoFactorBackupCodes\Listener\IListener; use OCA\TwoFactorBackupCodes\Listener\ProviderEnabled; use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater; @@ -67,6 +68,7 @@ class Application extends App { $listeners = [ $container->query(ActivityPublisher::class), $container->query(RegistryUpdater::class), + $container->query(ClearNotifications::class), ]; foreach ($listeners as $listener) { diff --git a/apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php b/apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php new file mode 100644 index 00000000000..ad7fd188ebc --- /dev/null +++ b/apps/twofactor_backupcodes/lib/Listener/ClearNotifications.php @@ -0,0 +1,51 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @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\TwoFactorBackupCodes\Listener; + +use OCA\TwoFactorBackupCodes\Event\CodesGenerated; +use OCP\Notification\IManager; +use Symfony\Component\EventDispatcher\Event; + +class ClearNotifications implements IListener { + + /** @var IManager */ + private $manager; + + public function __construct(IManager $manager) { + $this->manager = $manager; + } + + public function handle(Event $event) { + if (!($event instanceof CodesGenerated)) { + return; + } + + $notification = $this->manager->createNotification(); + $notification->setApp('twofactor_backupcodes') + ->setUser($event->getUser()->getUID()) + ->setObject('create', 'codes'); + $this->manager->markProcessed($notification); + } +} |