From 97c0f81a2ee6c909a17a5a875f2b289ea43b0eda Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 6 Aug 2024 21:41:52 +0200 Subject: [PATCH 1/3] allow multi-account in nc with oauth login --- dev/Knoin/AbstractViews.js | 5 ++--- dev/Knoin/Knoin.js | 2 +- dev/View/Popup/Compose.js | 8 ++++---- dev/View/Popup/Contacts.js | 4 ---- plugins/nextcloud/index.php | 7 +++++++ .../v/0.0.0/app/templates/Views/User/PopupsIdentity.html | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dev/Knoin/AbstractViews.js b/dev/Knoin/AbstractViews.js index 828318b300..409e44386e 100644 --- a/dev/Knoin/AbstractViews.js +++ b/dev/Knoin/AbstractViews.js @@ -60,10 +60,9 @@ export class AbstractViewPopup extends AbstractView this.keyScope.scope = name; this.modalVisible = ko.observable(false).extend({ rateLimit: 0 }); this.close = () => this.modalVisible(false); + this.tryToClose = () => (false === this.onClose()) || this.close(); addShortcut('escape,close', '', name, () => { - if (this.modalVisible() && false !== this.onClose()) { - this.close(); - } + this.modalVisible() && this.tryToClose(); return false; // return true; Issue with supported modal close }); diff --git a/dev/Knoin/Knoin.js b/dev/Knoin/Knoin.js index df348375c8..12d07d1cbe 100644 --- a/dev/Knoin/Knoin.js +++ b/dev/Knoin/Knoin.js @@ -167,7 +167,7 @@ const if (screenName && fireEvent('sm-show-screen', screenName + (subPart ? '/' + subPart : ''), 1)) { // Close all popups for (let vm of visiblePopups) { - (false === vm.onClose()) || vm.close(); + vm.tryToClose(); } let vmScreen = screen(screenName); diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 9c4e639545..3a875d5879 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -298,7 +298,7 @@ export class ComposePopupView extends AbstractViewPopup { ] }); - this.tryToClose = this.tryToClose.debounce(200); + this.doClose = this.doClose.debounce(200); this.iTimer = 0; @@ -665,7 +665,7 @@ export class ComposePopupView extends AbstractViewPopup { this.saveCommand(); } - this.tryToClose(); + this.doClose(); } contactsCommand() { @@ -1072,7 +1072,7 @@ export class ComposePopupView extends AbstractViewPopup { }, 100); } - tryToClose() { + doClose() { if (AskPopupView.hidden()) { if (ComposePopupView.inEdit() || (this.isEmptyForm() && !this.draftUid())) { this.close(); @@ -1218,7 +1218,7 @@ export class ComposePopupView extends AbstractViewPopup { }); addShortcut('escape,close', 'shift', ScopeCompose, () => { - this.tryToClose(); + this.doClose(); return false; }); diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 15b6d61f30..342a6d5049 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -314,10 +314,6 @@ export class ContactsPopupView extends AbstractViewPopup { } } - tryToClose() { - (false === this.onClose()) || this.close(); - } - onClose() { const contact = this.contact(); if (AskPopupView.hidden() && contact?.hasChanges()) { diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php index bb7c4f6860..c3a769eb6b 100644 --- a/plugins/nextcloud/index.php +++ b/plugins/nextcloud/index.php @@ -90,8 +90,15 @@ public function loginCredentials2(string &$sEmail, ?string &$sPassword = null) : public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings) : void { // https://apps.nextcloud.com/apps/oidc_login + $ocUser = \OC::$server->getUserSession()->getUser(); + $sNcEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress(); + + // Only login with OIDC access token if + // it is enabled in config, the user is currently logged in with OIDC + // and the current snappymail account is the OIDC account if (\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false) && \OC::$server->getSession()->get('is_oidc') + && $sNcEmail === $oSettings->username // && $oClient->supportsAuthType('OAUTHBEARER') // v2.28 ) { $sAccessToken = \OC::$server->getSession()->get('oidc_access_token'); diff --git a/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html b/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html index ebf739b656..201205a663 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html @@ -1,5 +1,5 @@
- × + ×

From ae74f21242e1c8e04db6730fec0284deb7793f9c Mon Sep 17 00:00:00 2001 From: Akhil Date: Thu, 8 Aug 2024 21:58:56 +0530 Subject: [PATCH 2/3] Also check if the account has been defined in setting --- plugins/nextcloud/index.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php index c3a769eb6b..80a0a8f667 100644 --- a/plugins/nextcloud/index.php +++ b/plugins/nextcloud/index.php @@ -90,15 +90,24 @@ public function loginCredentials2(string &$sEmail, ?string &$sPassword = null) : public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings) : void { // https://apps.nextcloud.com/apps/oidc_login - $ocUser = \OC::$server->getUserSession()->getUser(); - $sNcEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress(); + $config = \OC::$server->getConfig(); + $oUser = \OC::$server->getUserSession()->getUser(); + $sUID = $oUser->getUID(); + + $sEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email'); + $sPassword = $config->getUserValue($sUID, 'snappymail', 'passphrase') + ?: $config->getUserValue($sUID, 'snappymail', 'snappymail-password'); + $bAccountDefinedExplicitly = ($sEmail && $sPassword) && $sEmail === $oSettings->username; + + $sNcEmail = $oUser->getEMailAddress() ?: $oUser->getPrimaryEMailAddress(); // Only login with OIDC access token if - // it is enabled in config, the user is currently logged in with OIDC - // and the current snappymail account is the OIDC account + // it is enabled in config, the user is currently logged in with OIDC, + // the current snappymail account is the OIDC account and no account defined explicitly if (\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false) && \OC::$server->getSession()->get('is_oidc') && $sNcEmail === $oSettings->username + && !$bAccountDefinedExplicitly // && $oClient->supportsAuthType('OAUTHBEARER') // v2.28 ) { $sAccessToken = \OC::$server->getSession()->get('oidc_access_token'); From 50265b3b3794f820d35c07c70f6cb9b297f561b0 Mon Sep 17 00:00:00 2001 From: Akhil Date: Thu, 8 Aug 2024 22:09:34 +0530 Subject: [PATCH 3/3] Also perform logout if explicit creds change --- .../snappymail/lib/Controller/FetchController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/integrations/nextcloud/snappymail/lib/Controller/FetchController.php b/integrations/nextcloud/snappymail/lib/Controller/FetchController.php index af0dcd8fd6..2b33ad9459 100644 --- a/integrations/nextcloud/snappymail/lib/Controller/FetchController.php +++ b/integrations/nextcloud/snappymail/lib/Controller/FetchController.php @@ -119,12 +119,21 @@ public function setPersonal(): JSONResponse { ]); } + // Logout as the credentials have changed + SnappyMailHelper::loadApp(); + \RainLoop\Api::Actions()->DoLogout(); + return new JSONResponse([ 'status' => 'success', 'Message' => $this->l->t('Saved successfully'), 'Email' => $sEmail ]); } catch (Exception $e) { + // Logout as the credentials might have changed, as exception could be in one attribute + // TODO: Handle both exceptions separately? + SnappyMailHelper::loadApp(); + \RainLoop\Api::Actions()->DoLogout(); + return new JSONResponse([ 'status' => 'error', 'Message' => $e->getMessage()