From bd737a82bff3f1cff5a26ce6b7ebc01c5a44e245 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 24 Oct 2023 11:43:47 +0200 Subject: [PATCH] Improve solution for #1241 --- .../snappymail/lib/Util/SnappyMailHelper.php | 5 ++- plugins/proxyauth-login-example/index.php | 37 ++++++------------- .../app/libraries/RainLoop/Actions/User.php | 1 + .../libraries/RainLoop/Actions/UserAuth.php | 7 +++- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php index 8306cbcb4..d625a9c86 100644 --- a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php +++ b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php @@ -82,11 +82,14 @@ class SnappyMailHelper $oActions->Logger()->AddSecret($aCredentials[2]); $oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]); if ($oAccount) { + // Must be here due to bug #1241 + $oActions->SetMainAuthAccount($oAccount); + $oActions->Plugins()->RunHook('login.success', array($oAccount)); + $oActions->SetAuthToken($oAccount); if ($oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DEFAULT_OFF) === \RainLoop\Enumerations\SignMeType::DEFAULT_ON) { $oActions->SetSignMeToken($oAccount); } - $oActions->Plugins()->RunHook('login.success', array($oAccount)); } } catch (\Throwable $e) { // Login failure, reset password to prevent more attempts diff --git a/plugins/proxyauth-login-example/index.php b/plugins/proxyauth-login-example/index.php index bdab43fe9..e92cde71d 100644 --- a/plugins/proxyauth-login-example/index.php +++ b/plugins/proxyauth-login-example/index.php @@ -1,11 +1,13 @@ isValidAccount($oAccount->IncLogin(), $oAccount->IncPassword()); - - /** - * $oAccount->Email(); // Email (It is not a IMAP login) - * $oAccount->IncLogin(); // IMAP login - * $oAccount->IncPassword(); // IMAP password - * $oAccount->Domain()->IncHost(); // IMAP host - * - * @see \RainLoo\Model\Account for more - */ - - if (!$bValid) // if verify failed - { - // throw a Auth Error Exception - throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError); - } - else // Or setup your proxyauth admin account credentials - { - $oAccount->SetProxyAuthUser('admin@domain.com'); - $oAccount->SetProxyAuthPassword('secret-admin-password'); - } + // Verify logic + if (!$this->isValidAccount($oAccount->IncLogin(), $oAccount->IncPassword())) { + // throw a Auth Error Exception + throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError); } + + $oAccount->SetProxyAuthUser('admin@domain.com'); + $oAccount->SetProxyAuthPassword('secret-admin-password'); } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php index cf1a71774..867c55a3a 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php @@ -47,6 +47,7 @@ trait User } // Must be here due to bug #1241 + $this->SetMainAuthAccount($oAccount); $this->Plugins()->RunHook('login.success', array($oAccount)); $this->SetAuthToken($oAccount); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php index 8bef86a96..da8b0a8ca 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php @@ -290,10 +290,15 @@ trait UserAuth return $this->oMainAuthAccount; } - public function SetAuthToken(MainAccount $oAccount): void + public function SetMainAuthAccount(MainAccount $oAccount): void { $this->oAdditionalAuthAccount = false; $this->oMainAuthAccount = $oAccount; + } + + public function SetAuthToken(MainAccount $oAccount): void + { + $this->SetMainAuthAccount($oAccount); static::SetAccountCookie(self::AUTH_SPEC_TOKEN_KEY, $oAccount); }