Improve solution for #1241

This commit is contained in:
the-djmaze 2023-10-24 11:43:47 +02:00
parent 0064a44031
commit bd737a82bf
4 changed files with 22 additions and 28 deletions

View file

@ -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

View file

@ -1,11 +1,13 @@
<?php
use RainLoop\Model\MainAccount;
class ProxyauthLoginExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Proxy Auth Login Example',
VERSION = '2.2',
RELEASE = '2022-12-08',
RELEASE = '2023-10-24',
REQUIRED = '2.23.0',
CATEGORY = 'General',
DESCRIPTION = '';
@ -27,32 +29,15 @@ class ProxyauthLoginExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
/**
* @param \RainLoop\Model\Account $oAccount
*/
public function EventLoginPostLoginProvide(&$oAccount)
public function EventLoginPostLoginProvide(MainAccount $oAccount)
{
if ($oAccount instanceof \RainLoop\Model\Account)
{
// Verify logic
$bValid = $this->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');
}
}

View file

@ -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);

View file

@ -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);
}