Skip to content

Commit

Permalink
Resolve #969
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Feb 15, 2023
1 parent 8c97b64 commit 38c4b4e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
17 changes: 12 additions & 5 deletions integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@ public static function startApp(bool $handle = false) : void
}
*/
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
$oActions->Logger()->AddSecret($aCredentials[2]);
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2], false);
if ($oAccount) {
$oActions->Plugins()->RunHook('login.success', array($oAccount));
$oActions->SetAuthToken($oAccount);
try {
$oActions->Logger()->AddSecret($aCredentials[2]);
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2], false);
if ($oAccount) {
$oActions->Plugins()->RunHook('login.success', array($oAccount));
$oActions->SetAuthToken($oAccount);
}
} catch (\Throwable $e) {
// Login failure, reset password to prevent more attempts
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
\OC::$server->getSession()['snappymail-password'] = '';
\OC::$server->getConfig()->setUserValue($sUID, 'snappymail', 'snappymail-password', '');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function Connect(ConnectSettings $oSettings) : void

if ($this->IsConnected()) {
$this->writeLogException(new Exceptions\SocketAlreadyConnectedException, \LOG_ERR, false);
return;
$this->Disconnect();
}

$this->Settings = $oSettings;
Expand Down
7 changes: 6 additions & 1 deletion snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public function DoLogin() : array

$this->Logger()->AddSecret($sPassword);

$oAccount = $this->LoginProcess($sEmail, $sPassword, $bSignMe);
try {
$oAccount = $this->LoginProcess($sEmail, $sPassword, $bSignMe);
} catch (\Throwable $oException) {
$this->loginErrorDelay();
throw $oException;
}

$this->SetAuthToken($oAccount);

Expand Down
16 changes: 4 additions & 12 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public function LoginProcess(string &$sEmail, string &$sPassword, bool $bSignMe
$this->resolveLoginCredentials($sEmail, $sPassword, $sLogin);

if (!\str_contains($sEmail, '@') || !\strlen($sPassword)) {
$this->loginErrorDelay();
throw new ClientException(Notifications::InvalidInputArgument);
}

Expand All @@ -135,20 +134,13 @@ public function LoginProcess(string &$sEmail, string &$sPassword, bool $bSignMe
}
} catch (\Throwable $oException) {
$this->LoggerAuthHelper($oAccount, $this->getAdditionalLogParamsByUserLogin($sInputEmail));
$this->loginErrorDelay();
throw $oException;
}

try {
$this->imapConnect($oAccount, true);
if ($bMainAccount) {
$bSignMe && $this->SetSignMeToken($oAccount);
$this->StorageProvider()->Put($oAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true');
}
} catch (\Throwable $oException) {
$this->loginErrorDelay();

throw $oException;
$this->imapConnect($oAccount, true);
if ($bMainAccount) {
$bSignMe && $this->SetSignMeToken($oAccount);
$this->StorageProvider()->Put($oAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true');
}

return $oAccount;
Expand Down

0 comments on commit 38c4b4e

Please sign in to comment.