From 9c5cbe8e9cb954d4bf2ae67ec64b7c5020558cb8 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 25 Jul 2023 22:39:05 +0530 Subject: [PATCH 1/2] Basic error handling for autologin webmail --- .../BeforeTemplateRenderedListener.php | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php index 9c6369c3..1b399a92 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; } } -- GitLab From 0cf1894005a2869fae6cbc56b6c14fd614b5360f Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 25 Jul 2023 22:50:39 +0530 Subject: [PATCH 2/2] lint php --- lib/Listeners/BeforeTemplateRenderedListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php index 1b399a92..9325d4b6 100644 --- a/lib/Listeners/BeforeTemplateRenderedListener.php +++ b/lib/Listeners/BeforeTemplateRenderedListener.php @@ -55,7 +55,7 @@ class BeforeTemplateRenderedListener implements IEventListener { } $accountId = $this->getAccountId(); try { - $actions = \RainLoop\Api::Actions(); + $actions = \RainLoop\Api::Actions(); if (empty($accountId) || $actions->getMainAccountFromToken(false)) { return; } -- GitLab