From 3017f8c656c58d2101d0bef2029523f9f3899346 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 28 Mar 2024 02:43:39 +0100 Subject: [PATCH] Simplify LoginProcess handling --- .../snappymail/lib/Util/SnappyMailHelper.php | 11 ++--------- .../owncloud/snappymail/lib/Util/SnappyMailHelper.php | 4 ---- plugins/login-external/index.php | 10 ++++------ plugins/login-oauth2/index.php | 7 +++---- plugins/login-remote/index.php | 9 +++------ plugins/proxy-auth/index.php | 9 +++------ .../v/0.0.0/app/libraries/RainLoop/Actions/User.php | 5 ----- .../0.0.0/app/libraries/RainLoop/Actions/UserAuth.php | 6 ++++++ .../v/0.0.0/app/libraries/RainLoop/ServiceActions.php | 10 +++------- 9 files changed, 24 insertions(+), 47 deletions(-) diff --git a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php index 7d6016747..3c76ab627 100644 --- a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php +++ b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php @@ -92,15 +92,8 @@ class SnappyMailHelper if ($doLogin && $aCredentials[1] && $aCredentials[2]) { try { $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::DefaultOff) === \RainLoop\Enumerations\SignMeType::DefaultOn) { - $oActions->SetSignMeToken($oAccount); - } + if ($oAccount && $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DefaultOff) === \RainLoop\Enumerations\SignMeType::DefaultOn) { + $oActions->SetSignMeToken($oAccount); } } catch (\Throwable $e) { // Login failure, reset password to prevent more attempts diff --git a/integrations/owncloud/snappymail/lib/Util/SnappyMailHelper.php b/integrations/owncloud/snappymail/lib/Util/SnappyMailHelper.php index 04ac12bc1..8835da06c 100644 --- a/integrations/owncloud/snappymail/lib/Util/SnappyMailHelper.php +++ b/integrations/owncloud/snappymail/lib/Util/SnappyMailHelper.php @@ -142,10 +142,6 @@ class SnappyMailHelper if ($doLogin && $aCredentials[1] && $aCredentials[2]) { $oActions->Logger()->AddSecret($aCredentials[2]); $oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]); - if ($oAccount) { - $oActions->Plugins()->RunHook('login.success', array($oAccount)); - $oActions->SetAuthToken($oAccount); - } } } } catch (\Throwable $e) { diff --git a/plugins/login-external/index.php b/plugins/login-external/index.php index 609aaae81..001b11a9c 100644 --- a/plugins/login-external/index.php +++ b/plugins/login-external/index.php @@ -6,9 +6,9 @@ class LoginExternalPlugin extends \RainLoop\Plugins\AbstractPlugin NAME = 'Login External', AUTHOR = 'SnappyMail', URL = 'https://snappymail.eu/', - VERSION = '1.2', - RELEASE = '2023-03-14', - REQUIRED = '2.27.0', + VERSION = '1.3', + RELEASE = '2024-03-27', + REQUIRED = '2.36.1', CATEGORY = 'Login', LICENSE = 'MIT', DESCRIPTION = 'Login with $_POST["Email"] and $_POST["Password"] from anywhere'; @@ -32,9 +32,7 @@ class LoginExternalPlugin extends \RainLoop\Plugins\AbstractPlugin try { $oAccount = $oActions->LoginProcess($sEmail, $sPassword); - if ($oAccount instanceof \RainLoop\Model\MainAccount) { - $oActions->SetAuthToken($oAccount); - } else { + if (!$oAccount instanceof \RainLoop\Model\MainAccount) { $oAccount = null; } } diff --git a/plugins/login-oauth2/index.php b/plugins/login-oauth2/index.php index 6b4d8b1a2..99351c81b 100644 --- a/plugins/login-oauth2/index.php +++ b/plugins/login-oauth2/index.php @@ -4,9 +4,9 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin { const NAME = 'OAuth2', - VERSION = '1.2', - RELEASE = '2024-03-12', - REQUIRED = '2.35.3', + VERSION = '1.3', + RELEASE = '2024-03-27', + REQUIRED = '2.36.1', CATEGORY = 'Login', DESCRIPTION = 'IMAP, Sieve & SMTP login using RFC 7628 OAuth2'; @@ -91,7 +91,6 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin { $oAccount = $oActions->LoginProcess($sEmail, $sPassword); if ($oAccount instanceof \RainLoop\Model\Account) { - $oActions->AuthToken($oAccount); $iErrorCode = 0; } else { $oAccount = null; diff --git a/plugins/login-remote/index.php b/plugins/login-remote/index.php index 365700077..88635c9b3 100644 --- a/plugins/login-remote/index.php +++ b/plugins/login-remote/index.php @@ -6,9 +6,9 @@ class LoginRemotePlugin extends \RainLoop\Plugins\AbstractPlugin NAME = 'Login Remote', AUTHOR = 'SnappyMail', URL = 'https://snappymail.eu/', - VERSION = '1.3', - RELEASE = '2023-03-14', - REQUIRED = '2.27.0', + VERSION = '1.4', + RELEASE = '2024-03-27', + REQUIRED = '2.36.1', CATEGORY = 'Login', LICENSE = 'MIT', DESCRIPTION = 'Tries to login using the $_ENV["REMOTE_*"] variables'; @@ -44,9 +44,6 @@ class LoginRemotePlugin extends \RainLoop\Plugins\AbstractPlugin { static::$login = true; $oAccount = $oActions->LoginProcess($sEmail, $sPassword); - if ($oAccount instanceof \RainLoop\Model\MainAccount) { - $oActions->SetAuthToken($oAccount); - } } catch (\Throwable $oException) { diff --git a/plugins/proxy-auth/index.php b/plugins/proxy-auth/index.php index 5a6fc1227..ec0a40f6b 100644 --- a/plugins/proxy-auth/index.php +++ b/plugins/proxy-auth/index.php @@ -6,9 +6,9 @@ class ProxyAuthPlugin extends \RainLoop\Plugins\AbstractPlugin NAME = 'Proxy Auth', AUTHOR = 'Philipp', URL = 'https://www.mundhenk.org/', - VERSION = '0.2', - RELEASE = '2024-01-22', - REQUIRED = '2.27.0', + VERSION = '0.3', + RELEASE = '2024-03-27', + REQUIRED = '2.36.1', CATEGORY = 'Login', LICENSE = 'MIT', DESCRIPTION = 'Uses HTTP Remote-User and (Dovecot) master user for login'; @@ -124,9 +124,6 @@ class ProxyAuthPlugin extends \RainLoop\Plugins\AbstractPlugin { static::$login = true; $oAccount = $oActions->LoginProcess($sEmail, $sPassword); - if ($oAccount instanceof \RainLoop\Model\MainAccount) { - $oActions->SetAuthToken($oAccount); - } } catch (\Throwable $oException) { 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 8357f997d..7347d2b9c 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 @@ -45,11 +45,6 @@ trait User throw $oException; } - // Must be here due to bug #1241 - $this->SetMainAuthAccount($oAccount); - $this->Plugins()->RunHook('login.success', array($oAccount)); - - $this->SetAuthToken($oAccount); empty($this->GetActionParam('signMe', 0)) || $this->SetSignMeToken($oAccount); $sLanguage = $this->GetActionParam('language', ''); 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 540d69886..97649b80a 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 @@ -140,6 +140,12 @@ trait UserAuth $this->imapConnect($oAccount, true); if ($bMainAccount) { $this->StorageProvider()->Put($oAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true'); + + // Must be here due to bug #1241 + $this->SetMainAuthAccount($oAccount); + $this->Plugins()->RunHook('login.success', array($oAccount)); + + $this->SetAuthToken($oAccount); } return $oAccount; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index 667a01473..97c4c1806 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -563,7 +563,7 @@ class ServiceActions $oAccount = $this->oActions->LoginProcess($sEmail, $oPassword); if ($aAdditionalOptions) { - $bNeedToSettings = false; + $bSaveSettings = false; $oSettings = $this->SettingsProvider()->Load($oAccount); if ($oSettings) { @@ -573,20 +573,16 @@ class ServiceActions if ($sLanguage) { $sLanguage = $this->oActions->ValidateLanguage($sLanguage); if ($sLanguage !== $oSettings->GetConf('language', '')) { - $bNeedToSettings = true; + $bSaveSettings = true; $oSettings->SetConf('language', $sLanguage); } } } - if ($bNeedToSettings) { + if ($bSaveSettings) { $oSettings->save(); } } - - if ($oAccount instanceof Model\MainAccount) { - $this->oActions->SetAuthToken($oAccount); - } } catch (\Throwable $oException) {