diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php index 9c6369c362a2514df3aeeb43b41917997e2354b0..9325d4b6bdd1e4b669435c31fe976342455258d5 100644 --- a/lib/Listeners/BeforeTemplateRenderedListener.php +++ b/lib/Listeners/BeforeTemplateRenderedListener.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Listeners; +use Exception; use OCP\EventDispatcher\Event; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use \OCP\EventDispatcher\IEventListener; @@ -11,6 +12,7 @@ use OCP\IUserSession; use OCP\ISession; use OCP\IConfig; use OCP\IRequest; +use OCP\ILogger; use OCP\App\IAppManager; class BeforeTemplateRenderedListener implements IEventListener { @@ -20,13 +22,15 @@ class BeforeTemplateRenderedListener implements IEventListener { private $session; private $config; private $appManager; + private ILogger $logger; private const SNAPPYMAIL_APP_ID = 'snappymail'; private const SNAPPYMAIL_URL = '/apps/snappymail/'; private const SNAPPYMAIL_AUTOLOGIN_PWD = '1'; - public function __construct($appName, IUserSession $userSession, IRequest $request, ISession $session, IConfig $config, IAppManager $appManager) { + public function __construct($appName, ILogger $logger, IUserSession $userSession, IRequest $request, ISession $session, IConfig $config, IAppManager $appManager) { $this->appName = $appName; + $this->logger = $logger; $this->userSession = $userSession; $this->request = $request; $this->session = $session; @@ -50,18 +54,22 @@ class BeforeTemplateRenderedListener implements IEventListener { return; } $accountId = $this->getAccountId(); - $actions = \RainLoop\Api::Actions(); - - if (empty($accountId) || $actions->getMainAccountFromToken(false)) { - return; - } + try { + $actions = \RainLoop\Api::Actions(); + if (empty($accountId) || $actions->getMainAccountFromToken(false)) { + return; + } // Just send over '1' as password to trigger login as the plugin will set the correct access token - $password = self::SNAPPYMAIL_AUTOLOGIN_PWD; // As we cannot pass by reference to LoginProcess - $account = $actions->LoginProcess($accountId, $password, false); - if ($account) { - $actions->Plugins()->RunHook('login.success', array($account)); - $actions->SetAuthToken($account); + $password = self::SNAPPYMAIL_AUTOLOGIN_PWD; // As we cannot pass by reference to LoginProcess + $account = $actions->LoginProcess($accountId, $password, false); + if ($account) { + $actions->Plugins()->RunHook('login.success', array($account)); + $actions->SetAuthToken($account); + } + } catch(Exception $e) { + $this->logger->logException($e); + return; } }