mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-10 15:08:28 +03:00
Resolve #126
This commit is contained in:
parent
2fea7b92e1
commit
af08a9a301
2 changed files with 38 additions and 18 deletions
|
|
@ -221,7 +221,7 @@ trait UserAuth
|
|||
*/
|
||||
public function getMainAccountFromToken(bool $bThrowExceptionOnFalse = true): ?MainAccount
|
||||
{
|
||||
if (false === $this->oMainAuthAccount) {
|
||||
if (false === $this->oMainAuthAccount) try {
|
||||
$this->oMainAuthAccount = null;
|
||||
if (isset($_COOKIE[self::AUTH_SPEC_LOGOUT_TOKEN_KEY])) {
|
||||
Utils::ClearCookie(self::AUTH_SPEC_LOGOUT_TOKEN_KEY);
|
||||
|
|
@ -241,6 +241,7 @@ trait UserAuth
|
|||
// \MailSo\Base\Http::StatusHeader(401);
|
||||
$this->Logout(true);
|
||||
// $sAdditionalMessage = $this->StaticI18N('SESSION_UNDEFINED');
|
||||
\SnappyMail\Log::notice('TOKENS', 'SESSION_TOKEN empty');
|
||||
throw new ClientException(Notifications::InvalidToken, null, 'Session undefined');
|
||||
}
|
||||
$oMainAuthAccount = MainAccount::NewInstanceFromTokenArray(
|
||||
|
|
@ -270,13 +271,23 @@ trait UserAuth
|
|||
} else {
|
||||
$oAccount = $this->GetAccountFromSignMeToken();
|
||||
if ($oAccount) {
|
||||
$this->StorageProvider()->Put(
|
||||
$oAccount,
|
||||
StorageType::SESSION,
|
||||
Utils::GetSessionToken(),
|
||||
'true'
|
||||
);
|
||||
$this->SetAuthToken($oAccount);
|
||||
}
|
||||
}
|
||||
|
||||
if ($bThrowExceptionOnFalse && !$this->oMainAuthAccount) {
|
||||
if (!$this->oMainAuthAccount) {
|
||||
throw new ClientException(Notifications::InvalidToken, null, 'Account undefined');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
if ($bThrowExceptionOnFalse) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->oMainAuthAccount;
|
||||
|
|
@ -307,6 +318,7 @@ trait UserAuth
|
|||
if (isset($aResult['e'], $aResult['u']) && \SnappyMail\UUID::isValid($aResult['u'])) {
|
||||
return $aResult;
|
||||
}
|
||||
\SnappyMail\Log::notice(self::AUTH_SIGN_ME_TOKEN_KEY, 'invalid');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -353,20 +365,25 @@ trait UserAuth
|
|||
\base64_decode(\end($aTokenData)),
|
||||
$sAuthToken
|
||||
]);
|
||||
|
||||
$oAccount = \is_array($aAccountHash)
|
||||
? MainAccount::NewInstanceFromTokenArray($this, $aAccountHash) : null;
|
||||
if ($oAccount) {
|
||||
$this->CheckMailConnection($oAccount);
|
||||
// Update lifetime
|
||||
$this->SetSignMeToken($oAccount);
|
||||
|
||||
return $oAccount;
|
||||
if (\is_array($aAccountHash)) {
|
||||
$oAccount = MainAccount::NewInstanceFromTokenArray($this, $aAccountHash);
|
||||
if ($oAccount) {
|
||||
$this->CheckMailConnection($oAccount);
|
||||
// Update lifetime
|
||||
$this->SetSignMeToken($oAccount);
|
||||
return $oAccount;
|
||||
}
|
||||
\SnappyMail\Log::notice(self::AUTH_SIGN_ME_TOKEN_KEY, 'has no account');
|
||||
} else {
|
||||
\SnappyMail\Log::notice(self::AUTH_SIGN_ME_TOKEN_KEY, 'decrypt failed');
|
||||
}
|
||||
} else {
|
||||
\SnappyMail\Log::notice(self::AUTH_SIGN_ME_TOKEN_KEY, "server token not found for {$aTokenData['e']}/.sign_me/{$aTokenData['u']}");
|
||||
}
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
\SnappyMail\Log::notice(self::AUTH_SIGN_ME_TOKEN_KEY, $oException->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,13 +96,6 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
|
|||
$iStorageType = StorageType::NOBODY;
|
||||
} else if ($mAccount instanceof \RainLoop\Model\MainAccount) {
|
||||
$sEmail = $mAccount->Email();
|
||||
if (StorageType::SIGN_ME === $iStorageType) {
|
||||
$sSubFolder = '.sign_me';
|
||||
} else if (StorageType::SESSION === $iStorageType) {
|
||||
$sSubFolder = '.sessions';
|
||||
} else if (StorageType::PGP === $iStorageType) {
|
||||
$sSubFolder = '.pgp';
|
||||
}
|
||||
} else if ($mAccount instanceof \RainLoop\Model\AdditionalAccount) {
|
||||
$sEmail = $mAccount->ParentEmail();
|
||||
if ($this->bLocal && !$bForDeleteAction) {
|
||||
|
|
@ -112,6 +105,16 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
|
|||
$sEmail = $mAccount;
|
||||
}
|
||||
|
||||
if ($sEmail) {
|
||||
if (StorageType::SIGN_ME === $iStorageType) {
|
||||
$sSubFolder = '.sign_me';
|
||||
} else if (StorageType::SESSION === $iStorageType) {
|
||||
$sSubFolder = '.sessions';
|
||||
} else if (StorageType::PGP === $iStorageType) {
|
||||
$sSubFolder = '.pgp';
|
||||
}
|
||||
}
|
||||
|
||||
$sFilePath = '';
|
||||
switch ($iStorageType)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue