diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php index 5dee093225b25faaec8a62dc518f8775867047b3..63fb7e96c4a45a50fc8a9b597ae54c1d94515290 100644 --- a/lib/Listeners/BeforeTemplateRenderedListener.php +++ b/lib/Listeners/BeforeTemplateRenderedListener.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace OCA\EmailRecovery\Listeners; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -use OCP\IUserSession; use OCP\Util; use OCA\EmailRecovery\Service\RecoveryEmailService; @@ -19,10 +19,9 @@ class BeforeTemplateRenderedListener implements IEventListener { private $userId; - public function __construct($appName, $userId, IUserSession $userSession, Util $util, RecoveryEmailService $recoveryEmailService) { + public function __construct($appName, $userId, Util $util, RecoveryEmailService $recoveryEmailService) { $this->appName = $appName; $this->userId = $userId; - $this->userSession = $userSession; $this->util = $util; $this->recoveryEmailService = $recoveryEmailService; } @@ -31,7 +30,7 @@ class BeforeTemplateRenderedListener implements IEventListener { if (!($event instanceof BeforeTemplateRenderedEvent)) { return; } - if ($this->userSession->isLoggedIn() && !empty($this->userId)) { + if (($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_USER) && $event->isLoggedIn() && !empty($this->userId)) { $recoveryEmail = $this->recoveryEmailService->getRecoveryEmail($this->userId); if ($recoveryEmail === '') { $this->util->addStyle($this->appName, 'email-recovery');