Simplify LoginProcess handling

This commit is contained in:
the-djmaze 2024-03-28 02:43:39 +01:00
parent 6be84f8ab4
commit 3017f8c656
9 changed files with 24 additions and 47 deletions

View file

@ -92,15 +92,8 @@ class SnappyMailHelper
if ($doLogin && $aCredentials[1] && $aCredentials[2]) { if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
try { try {
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]); $oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
if ($oAccount) { if ($oAccount && $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DefaultOff) === \RainLoop\Enumerations\SignMeType::DefaultOn) {
// Must be here due to bug #1241 $oActions->SetSignMeToken($oAccount);
$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);
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
// Login failure, reset password to prevent more attempts // Login failure, reset password to prevent more attempts

View file

@ -142,10 +142,6 @@ class SnappyMailHelper
if ($doLogin && $aCredentials[1] && $aCredentials[2]) { if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
$oActions->Logger()->AddSecret($aCredentials[2]); $oActions->Logger()->AddSecret($aCredentials[2]);
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]); $oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
if ($oAccount) {
$oActions->Plugins()->RunHook('login.success', array($oAccount));
$oActions->SetAuthToken($oAccount);
}
} }
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {

View file

@ -6,9 +6,9 @@ class LoginExternalPlugin extends \RainLoop\Plugins\AbstractPlugin
NAME = 'Login External', NAME = 'Login External',
AUTHOR = 'SnappyMail', AUTHOR = 'SnappyMail',
URL = 'https://snappymail.eu/', URL = 'https://snappymail.eu/',
VERSION = '1.2', VERSION = '1.3',
RELEASE = '2023-03-14', RELEASE = '2024-03-27',
REQUIRED = '2.27.0', REQUIRED = '2.36.1',
CATEGORY = 'Login', CATEGORY = 'Login',
LICENSE = 'MIT', LICENSE = 'MIT',
DESCRIPTION = 'Login with $_POST["Email"] and $_POST["Password"] from anywhere'; DESCRIPTION = 'Login with $_POST["Email"] and $_POST["Password"] from anywhere';
@ -32,9 +32,7 @@ class LoginExternalPlugin extends \RainLoop\Plugins\AbstractPlugin
try try
{ {
$oAccount = $oActions->LoginProcess($sEmail, $sPassword); $oAccount = $oActions->LoginProcess($sEmail, $sPassword);
if ($oAccount instanceof \RainLoop\Model\MainAccount) { if (!$oAccount instanceof \RainLoop\Model\MainAccount) {
$oActions->SetAuthToken($oAccount);
} else {
$oAccount = null; $oAccount = null;
} }
} }

View file

@ -4,9 +4,9 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
{ {
const const
NAME = 'OAuth2', NAME = 'OAuth2',
VERSION = '1.2', VERSION = '1.3',
RELEASE = '2024-03-12', RELEASE = '2024-03-27',
REQUIRED = '2.35.3', REQUIRED = '2.36.1',
CATEGORY = 'Login', CATEGORY = 'Login',
DESCRIPTION = 'IMAP, Sieve & SMTP login using RFC 7628 OAuth2'; DESCRIPTION = 'IMAP, Sieve & SMTP login using RFC 7628 OAuth2';
@ -91,7 +91,6 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
{ {
$oAccount = $oActions->LoginProcess($sEmail, $sPassword); $oAccount = $oActions->LoginProcess($sEmail, $sPassword);
if ($oAccount instanceof \RainLoop\Model\Account) { if ($oAccount instanceof \RainLoop\Model\Account) {
$oActions->AuthToken($oAccount);
$iErrorCode = 0; $iErrorCode = 0;
} else { } else {
$oAccount = null; $oAccount = null;

View file

@ -6,9 +6,9 @@ class LoginRemotePlugin extends \RainLoop\Plugins\AbstractPlugin
NAME = 'Login Remote', NAME = 'Login Remote',
AUTHOR = 'SnappyMail', AUTHOR = 'SnappyMail',
URL = 'https://snappymail.eu/', URL = 'https://snappymail.eu/',
VERSION = '1.3', VERSION = '1.4',
RELEASE = '2023-03-14', RELEASE = '2024-03-27',
REQUIRED = '2.27.0', REQUIRED = '2.36.1',
CATEGORY = 'Login', CATEGORY = 'Login',
LICENSE = 'MIT', LICENSE = 'MIT',
DESCRIPTION = 'Tries to login using the $_ENV["REMOTE_*"] variables'; DESCRIPTION = 'Tries to login using the $_ENV["REMOTE_*"] variables';
@ -44,9 +44,6 @@ class LoginRemotePlugin extends \RainLoop\Plugins\AbstractPlugin
{ {
static::$login = true; static::$login = true;
$oAccount = $oActions->LoginProcess($sEmail, $sPassword); $oAccount = $oActions->LoginProcess($sEmail, $sPassword);
if ($oAccount instanceof \RainLoop\Model\MainAccount) {
$oActions->SetAuthToken($oAccount);
}
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {

View file

@ -6,9 +6,9 @@ class ProxyAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
NAME = 'Proxy Auth', NAME = 'Proxy Auth',
AUTHOR = 'Philipp', AUTHOR = 'Philipp',
URL = 'https://www.mundhenk.org/', URL = 'https://www.mundhenk.org/',
VERSION = '0.2', VERSION = '0.3',
RELEASE = '2024-01-22', RELEASE = '2024-03-27',
REQUIRED = '2.27.0', REQUIRED = '2.36.1',
CATEGORY = 'Login', CATEGORY = 'Login',
LICENSE = 'MIT', LICENSE = 'MIT',
DESCRIPTION = 'Uses HTTP Remote-User and (Dovecot) master user for login'; DESCRIPTION = 'Uses HTTP Remote-User and (Dovecot) master user for login';
@ -124,9 +124,6 @@ class ProxyAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
{ {
static::$login = true; static::$login = true;
$oAccount = $oActions->LoginProcess($sEmail, $sPassword); $oAccount = $oActions->LoginProcess($sEmail, $sPassword);
if ($oAccount instanceof \RainLoop\Model\MainAccount) {
$oActions->SetAuthToken($oAccount);
}
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {

View file

@ -45,11 +45,6 @@ trait User
throw $oException; 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); empty($this->GetActionParam('signMe', 0)) || $this->SetSignMeToken($oAccount);
$sLanguage = $this->GetActionParam('language', ''); $sLanguage = $this->GetActionParam('language', '');

View file

@ -140,6 +140,12 @@ trait UserAuth
$this->imapConnect($oAccount, true); $this->imapConnect($oAccount, true);
if ($bMainAccount) { if ($bMainAccount) {
$this->StorageProvider()->Put($oAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true'); $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; return $oAccount;

View file

@ -563,7 +563,7 @@ class ServiceActions
$oAccount = $this->oActions->LoginProcess($sEmail, $oPassword); $oAccount = $this->oActions->LoginProcess($sEmail, $oPassword);
if ($aAdditionalOptions) { if ($aAdditionalOptions) {
$bNeedToSettings = false; $bSaveSettings = false;
$oSettings = $this->SettingsProvider()->Load($oAccount); $oSettings = $this->SettingsProvider()->Load($oAccount);
if ($oSettings) { if ($oSettings) {
@ -573,20 +573,16 @@ class ServiceActions
if ($sLanguage) { if ($sLanguage) {
$sLanguage = $this->oActions->ValidateLanguage($sLanguage); $sLanguage = $this->oActions->ValidateLanguage($sLanguage);
if ($sLanguage !== $oSettings->GetConf('language', '')) { if ($sLanguage !== $oSettings->GetConf('language', '')) {
$bNeedToSettings = true; $bSaveSettings = true;
$oSettings->SetConf('language', $sLanguage); $oSettings->SetConf('language', $sLanguage);
} }
} }
} }
if ($bNeedToSettings) { if ($bSaveSettings) {
$oSettings->save(); $oSettings->save();
} }
} }
if ($oAccount instanceof Model\MainAccount) {
$this->oActions->SetAuthToken($oAccount);
}
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {