diff --git a/lib/Listeners/UserConfigChangedListener.php b/lib/Listeners/UserConfigChangedListener.php index bfce357f17f6133ff8820bb74c25c707a9dbe153..02b8207b4eb283da5342e18928360274e732de3f 100644 --- a/lib/Listeners/UserConfigChangedListener.php +++ b/lib/Listeners/UserConfigChangedListener.php @@ -29,6 +29,7 @@ class UserConfigChangedListener implements IEventListener { if ($newRecoveryEmail !== '') { $this->recoveryEmailService->setRecoveryEmail($user, ''); $this->recoveryEmailService->sendVerificationEmail($user, $newRecoveryEmail); + $this->recoveryEmailService->addToJobList($user); } } } diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index 31f3156da87c2739535ca521071f49557e7a8d26..51439d90228ce12fbededa3353e7e66f04c97518 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -20,6 +20,8 @@ use OCP\L10N\IFactory; use OCP\IURLGenerator; use OCP\Defaults; use OCP\Security\VerificationToken\IVerificationToken; +use OCA\MurenaNotifications\BackgroundJob\WeeklyRecoveryNotificationJob; +use OCP\BackgroundJob\IJobList; class RecoveryEmailService { private ILogger $logger; @@ -33,8 +35,9 @@ class RecoveryEmailService { private Defaults $themingDefaults; private IVerificationToken $verificationToken; protected const TOKEN_LIFETIME = 60 * 30; // 30 minutes + private IJobList $jobList; - public function __construct(string $appName, ILogger $logger, IConfig $config, LDAPConnectionService $LDAPConnectionService, IUserManager $userManager, IMailer $mailer, IFactory $l10nFactory, IURLGenerator $urlGenerator, Defaults $themingDefaults, IVerificationToken $verificationToken) { + public function __construct(string $appName, ILogger $logger, IConfig $config, LDAPConnectionService $LDAPConnectionService, IUserManager $userManager, IMailer $mailer, IFactory $l10nFactory, IURLGenerator $urlGenerator, Defaults $themingDefaults, IVerificationToken $verificationToken, IJobList $jobList) { $this->logger = $logger; $this->config = $config; $this->appName = $appName; @@ -45,6 +48,7 @@ class RecoveryEmailService { $this->urlGenerator = $urlGenerator; $this->themingDefaults = $themingDefaults; $this->verificationToken = $verificationToken; + $this->jobList = $jobList; } public function setRecoveryEmail(string $username, string $value = '') : void { $this->config->setUserValue($username, $this->appName, 'recovery-email', $value); @@ -196,4 +200,13 @@ class RecoveryEmailService { $this->deleteUnverifiedRecoveryEmail($userId); } } + public function addToJobList(string $users): void { + // Add user to job list if not already there + // email job + $messageId = '20240101_weekly_reminder'; + $this->jobList->add(WeeklyRecoveryNotificationJob::class, [ + 'users' => $users, + 'messageId' => $messageId + ]); + } }