summaryrefslogtreecommitdiffstats
path: root/apps/twofactor_backupcodes/lib/AppInfo
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-09-29 20:56:23 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-10-01 15:35:25 +0200
commit956fe1b86769c1a8a380a61ba72441f0e334e36a (patch)
tree5aa810228ca324dfe2d12a1f94f213d9ab657345 /apps/twofactor_backupcodes/lib/AppInfo
parenta95154642dd6535ebddebef4e6562e777f2094a4 (diff)
downloadnextcloud-server-956fe1b86769c1a8a380a61ba72441f0e334e36a.tar.gz
nextcloud-server-956fe1b86769c1a8a380a61ba72441f0e334e36a.zip
Generate backups code notification if not enable but 2fa is
Generate a notification to generate backup codes if you enable an other 2FA provider but backup codes are not yet generated. * Add event listner * Insert background job * Background job tests and emits notification every 2 weeks * If the backup codes are generated the next run will remove the job Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/twofactor_backupcodes/lib/AppInfo')
-rw-r--r--apps/twofactor_backupcodes/lib/AppInfo/Application.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/apps/twofactor_backupcodes/lib/AppInfo/Application.php b/apps/twofactor_backupcodes/lib/AppInfo/Application.php
index d2541d87627..1af114a2791 100644
--- a/apps/twofactor_backupcodes/lib/AppInfo/Application.php
+++ b/apps/twofactor_backupcodes/lib/AppInfo/Application.php
@@ -29,8 +29,14 @@ use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher;
use OCA\TwoFactorBackupCodes\Listener\IListener;
+use OCA\TwoFactorBackupCodes\Listener\ProviderEnabled;
use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater;
+use OCA\TwoFactorBackupCodes\Notifications\Notifier;
use OCP\AppFramework\App;
+use OCP\Authentication\TwoFactorAuth\IRegistry;
+use OCP\Authentication\TwoFactorAuth\RegistryEvent;
+use OCP\IL10N;
+use OCP\Notification\IManager;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -44,6 +50,7 @@ class Application extends App {
*/
public function register() {
$this->registerHooksAndEvents();
+ $this->registerNotification();
}
/**
@@ -66,6 +73,27 @@ class Application extends App {
$listener->handle($event);
}
});
+
+ $eventDispatcher->addListener(IRegistry::EVENT_PROVIDER_ENABLED, function(RegistryEvent $event) use ($container) {
+ /** @var IListener $listener */
+ $listener = $container->query(ProviderEnabled::class);
+ $listener->handle($event);
+ });
+ }
+
+ public function registerNotification() {
+ $container = $this->getContainer();
+ /** @var IManager $manager */
+ $manager = $container->query(IManager::class);
+ $manager->registerNotifier(
+ function() use ($container) {
+ return $container->query(Notifier::class);
+ },
+ function () use ($container) {
+ $l = $container->query(IL10N::class);
+ return ['id' => 'twofactor_backupcodes', 'name' => $l->t('Second-factor backup codes')];
+ }
+ );
}
public function deleteUser($params) {