From 075ee88db6cf11225092665861eaac0b1d8dd73a Mon Sep 17 00:00:00 2001 From: nfebe Date: Thu, 12 Mar 2026 12:40:01 +0100 Subject: [PATCH] fix(invite): Add logging and fix decryption key in InviteService sendInvite() will silently return false with no logging when the lostpassword token is missing. Added warning/error logs and fixed decryption key to use getEMailAddress() matching GuestManager encryption. Aslo removed dead code in Hooks.php. Signed-off-by: nfebe # Conflicts: # lib/Hooks.php --- lib/Listener/ShareCreatedListener.php | 1 - lib/Service/InviteService.php | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Listener/ShareCreatedListener.php b/lib/Listener/ShareCreatedListener.php index 5598ba2b..6061f23f 100644 --- a/lib/Listener/ShareCreatedListener.php +++ b/lib/Listener/ShareCreatedListener.php @@ -73,7 +73,6 @@ public function handle(Event $event): void { } $user = $this->userSession->getUser(); - $this->userManager->get($shareWith); if (!$user) { throw new \Exception( diff --git a/lib/Service/InviteService.php b/lib/Service/InviteService.php index 58804689..f6fc4fa9 100644 --- a/lib/Service/InviteService.php +++ b/lib/Service/InviteService.php @@ -12,6 +12,7 @@ use OCA\Guests\Mail; use OCP\AppFramework\Db\DoesNotExistException; use OCP\IConfig; +use OCP\IUserManager; use OCP\Security\ICrypto; use OCP\Share\IShare; use Psr\Log\LoggerInterface; @@ -21,6 +22,7 @@ public function __construct( private readonly LoggerInterface $logger, private readonly IConfig $config, private readonly ICrypto $crypto, + private readonly IUserManager $userManager, private readonly Mail $mail, ) { } @@ -29,15 +31,23 @@ public function sendInvite(string $userId, string $guest, ?IShare $share = null) $passwordToken = $this->config->getUserValue($guest, 'core', 'lostpassword', null); if (!$passwordToken) { + $this->logger->warning('No password token found for guest "' . $guest . '", skipping invitation email'); return false; } try { - // user has not yet activated their account - $decryptedToken = $this->crypto->decrypt($passwordToken, strtolower($guest) . $this->config->getSystemValue('secret')); + $targetUser = $this->userManager->get($guest); + if ($targetUser === null) { + $this->logger->error('Guest user "' . $guest . '" not found'); + return false; + } + + $decryptedToken = $this->crypto->decrypt( + $passwordToken, + strtolower($targetUser->getEMailAddress()) . $this->config->getSystemValue('secret') + ); [, $token] = explode(':', $decryptedToken); $lang = $this->config->getUserValue($guest, 'core', 'lang', ''); - // send invitation $this->mail->sendGuestInviteMail( $userId, $guest,