diff --git a/dev/Remote/AbstractFetch.js b/dev/Remote/AbstractFetch.js index 85a4c5847..a0498e15b 100644 --- a/dev/Remote/AbstractFetch.js +++ b/dev/Remote/AbstractFetch.js @@ -1,30 +1,28 @@ import { Notification } from 'Common/Enums'; import { isArray, pInt, pString } from 'Common/Utils'; import { serverRequest } from 'Common/Links'; +import { getNotification } from 'Common/Translator'; -let iJsonErrorCount = 0, - iTokenErrorCount = 0; +let iJsonErrorCount = 0; const getURL = (add = '') => serverRequest('Json') + add, checkResponseError = data => { const err = data ? data.ErrorCode : null; - if (Notification.InvalidToken === err && 10 < ++iTokenErrorCount) { + if (Notification.InvalidToken === err) { + alert(getNotification(err)); rl.logoutReload(); - } else { - if ([ - Notification.AuthError, - Notification.ConnectionError, - Notification.DomainNotAllowed, - Notification.AccountNotAllowed, - Notification.MailServerError, - Notification.UnknownNotification, - Notification.UnknownError - ].includes(err) - ) { - ++iJsonErrorCount; - } - if (data.Logout || 7 < iJsonErrorCount) { + } else if ([ + Notification.AuthError, + Notification.ConnectionError, + Notification.DomainNotAllowed, + Notification.AccountNotAllowed, + Notification.MailServerError, + Notification.UnknownNotification, + Notification.UnknownError + ].includes(err) + ) { + if (7 < ++iJsonErrorCount) { rl.logoutReload(); } } @@ -158,7 +156,7 @@ export class AbstractFetchRemote } */ if (data.Result) { - iJsonErrorCount = iTokenErrorCount = 0; + iJsonErrorCount = 0; } else { checkResponseError(data); iError = data.ErrorCode || Notification.UnknownError diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 4d471d9fe..b09091862 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -1439,6 +1439,9 @@ class Actions } } + /** + * @throws \RainLoop\Exceptions\ClientException + */ private function initMailClientConnection(): ?Model\Account { $oAccount = null; 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 7dbe8b33d..32dcd108d 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 @@ -240,7 +240,8 @@ trait UserAuth if (!isset($_COOKIE[Utils::SESSION_TOKEN])) { // \MailSo\Base\Http::StatusHeader(401); $this->Logout(true); - throw new ClientException(Notifications::InvalidToken, null, 'Session undefined', true); +// $sAdditionalMessage = $this->StaticI18N('SESSION_UNDEFINED'); + throw new ClientException(Notifications::InvalidToken, null, 'Session undefined'); } $oMainAuthAccount = MainAccount::NewInstanceFromTokenArray( $this, @@ -255,7 +256,8 @@ trait UserAuth Utils::ClearCookie(Utils::SESSION_TOKEN); // \MailSo\Base\Http::StatusHeader(401); $this->Logout(true); - throw new ClientException(Notifications::AuthError, null, 'Session gone', true); +// $sAdditionalMessage = $this->StaticI18N('SESSION_GONE'); + throw new ClientException(Notifications::InvalidToken, null, 'Session gone'); } } else { $oAccount = $this->GetAccountFromSignMeToken(); @@ -268,7 +270,7 @@ trait UserAuth // Extend session cookie lifetime $this->StorageProvider()->Put($this->oMainAuthAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true'); } else if ($bThrowExceptionOnFalse) { - throw new ClientException(Notifications::AuthError); + throw new ClientException(Notifications::InvalidToken, null, 'Account undefined'); } } @@ -425,8 +427,7 @@ trait UserAuth } if ($this->Config()->Get('labs', 'imap_show_login_alert', true)) { - throw new ClientException(Notifications::AuthError, - $oException, $oException->getAlertFromStatus()); + throw new ClientException(Notifications::AuthError, $oException, $oException->getAlertFromStatus()); } else { throw new ClientException(Notifications::AuthError, $oException); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php index 7827bd261..4ea81ca7b 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php @@ -8,42 +8,21 @@ namespace RainLoop\Exceptions; */ class ClientException extends Exception { - /** - * @var bool - */ - private $bLogoutOnException; - /** * @var string */ private $sAdditionalMessage; - public function __construct(int $iCode, ?\Throwable $oPrevious = null, string $sAdditionalMessage = '', bool $bLogoutOnException = false) + public function __construct(int $iCode, ?\Throwable $oPrevious = null, string $sAdditionalMessage = '') { parent::__construct(\RainLoop\Notifications::GetNotificationsMessage($iCode, $oPrevious), $iCode, $oPrevious); $this->sAdditionalMessage = $sAdditionalMessage ?: ($oPrevious ? $oPrevious->getMessage() : ''); - - $this->bLogoutOnException = $bLogoutOnException; } public function getAdditionalMessage() : string { return $this->sAdditionalMessage; } - - public function getLogoutOnException() : bool - { - return $this->bLogoutOnException; - } - - public function setLogoutOnException(bool $bLogoutOnException, string $sAdditionalLogoutMessage = '') : self - { - $this->bLogoutOnException = $bLogoutOnException; - - $this->sAdditionalMessage = $sAdditionalLogoutMessage; - - return $this; - } } 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 f0f42d2fe..743ca8f6f 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -95,7 +95,7 @@ class ServiceActions $this->Config()->Get('security', 'csrf_protection', false) && ($_POST['XToken'] ?? '') !== Utils::GetCsrfToken()) { - throw new Exceptions\ClientException(Notifications::InvalidToken); + throw new Exceptions\ClientException(Notifications::InvalidToken, null, 'CSRF failed'); } else if (!empty($sAction)) { @@ -165,18 +165,6 @@ class ServiceActions $aResponseItem = $this->oActions->ExceptionResponse( empty($sAction) ? 'Unknown' : $sAction, $oException); - - if (\is_array($aResponseItem) && $oException instanceof Exceptions\ClientException) - { - if ($oException->getLogoutOnException()) - { - $aResponseItem['Logout'] = true; - if ($oException->getAdditionalMessage()) - { - $this->oActions->SetSpecLogoutCustomMgsWithDeletion($oException->getAdditionalMessage()); - } - } - } } if (\is_array($aResponseItem))