Added MainAccount class for better distinguishing it from the additional ones

This commit is contained in:
djmaze 2021-11-12 01:04:11 +01:00
parent 42bf782c6a
commit 0de87e334c
9 changed files with 48 additions and 57 deletions

View file

@ -1420,7 +1420,7 @@ class Actions
$sFolderFullNameRaw = $this->GetActionParam('Folder', '');
$_FILES = isset($_FILES) ? $_FILES : null;
if ($oAccount instanceof Model\Account &&
if ($oAccount &&
$this->Config()->Get('labs', 'allow_message_append', false) &&
isset($_FILES, $_FILES['AppendFile'], $_FILES['AppendFile']['name'],
$_FILES['AppendFile']['tmp_name'], $_FILES['AppendFile']['size'])) {

View file

@ -5,6 +5,7 @@ namespace RainLoop\Actions;
use RainLoop\Enumerations\Capa;
use RainLoop\Exceptions\ClientException;
use RainLoop\Model\Account;
use RainLoop\Model\MainAccount;
use RainLoop\Model\AdditionalAccount;
use RainLoop\Model\Identity;
use RainLoop\Notifications;
@ -19,11 +20,8 @@ trait Accounts
return $oAccount instanceof AdditionalAccount ? $oAccount->ParentEmail() : $oAccount->Email();
}
public function GetAccounts(Account $oAccount): array
public function GetAccounts(MainAccount $oAccount): array
{
if (\is_subclass_of($oAccount, 'RainLoop\\Model\\Account')) {
throw new \LogicException('Only main account can have sub accounts');
}
if ($this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) {
$sAccounts = $this->StorageProvider()->Get($oAccount,
StorageType::CONFIG,
@ -41,7 +39,7 @@ trait Accounts
/**
* Attempt to convert the old less secure data into better secured data
*/
protected function ConvertInsecureAccounts(Account $oMainAccount) : array
protected function ConvertInsecureAccounts(MainAccount $oMainAccount) : array
{
$sAccounts = $this->StorageProvider()->Get($oMainAccount, StorageType::CONFIG, 'accounts');
if (!$sAccounts || '{' !== $sAccounts[0]) {
@ -113,11 +111,8 @@ trait Accounts
return $aNewAccounts;
}
protected function SetAccounts(Account $oAccount, array $aAccounts = array()): void
protected function SetAccounts(MainAccount $oAccount, array $aAccounts = array()): void
{
if (\is_subclass_of($oAccount, 'RainLoop\\Model\\Account')) {
throw new \LogicException('Only main account can have sub accounts');
}
$sParentEmail = $oAccount->Email();
if ($aAccounts) {
$this->StorageProvider()->Put(
@ -303,10 +298,9 @@ trait Accounts
}
/**
* @param Account $oAccount
* @return Identity[]
*/
public function GetIdentities(Account $oAccount): array
public function GetIdentities(MainAccount $oAccount): array
{
// A custom name for a single identity is also stored in this system
$allowMultipleIdentities = $this->GetCapa(false, Capa::IDENTITIES, $oAccount);

View file

@ -323,7 +323,7 @@ trait Contacts
$this->AddressBookProvider($oAccount)->Export($this->GetMainEmail($oAccount), 'csv') : false;
}
private function importContactsFromVcfFile(Model\Account $oAccount, /*resource*/ $rFile): int
private function importContactsFromVcfFile(\RainLoop\Model\Account $oAccount, /*resource*/ $rFile): int
{
$iCount = 0;
if ($oAccount && \is_resource($rFile)) {

View file

@ -201,15 +201,13 @@ trait User
public function DoLogout() : array
{
$oAccount = $this->getAccountFromToken(false);
if ($oAccount)
{
if (!\is_subclass_of($oAccount, 'RainLoop\\Model\\Account'))
{
if ($oAccount) {
if ($oAccount instanceof \RainLoop\Model\MainAccount) {
$this->ClearSignMeData();
Utils::ClearCookie(self::AUTH_SPEC_TOKEN_KEY);
}
Utils::ClearCookie(self::AUTH_ADDITIONAL_TOKEN_KEY);
}
return $this->TrueResponse(__FUNCTION__);
}

View file

@ -5,6 +5,7 @@ namespace RainLoop\Actions;
use RainLoop\Notifications;
use RainLoop\Utils;
use RainLoop\Model\Account;
use RainLoop\Model\MainAccount;
use RainLoop\Model\AdditionalAccount;
use RainLoop\Providers\Storage\Enumerations\StorageType;
use RainLoop\Exceptions\ClientException;
@ -119,7 +120,7 @@ trait UserAuth
$oAccount->SetParentEmail($oMainAccount->Email());
}
} else {
$oAccount = Account::NewInstanceByLogin($this, $sEmail, $sLogin, $sPassword, $sClientCert, true);
$oAccount = MainAccount::NewInstanceByLogin($this, $sEmail, $sLogin, $sPassword, $sClientCert, true);
}
if (!$oAccount) {
@ -197,11 +198,9 @@ trait UserAuth
}
/**
* Returns RainLoop\Model\Account when it exists, else null
*
* @throws \RainLoop\Exceptions\ClientException
*/
public function getMainAccountFromToken(bool $bThrowExceptionOnFalse = true): ?Account
public function getMainAccountFromToken(bool $bThrowExceptionOnFalse = true): ?MainAccount
{
if (!$this->oMainAuthAccount) {
if (isset($_COOKIE[self::AUTH_SPEC_LOGOUT_TOKEN_KEY])) {
@ -213,7 +212,7 @@ trait UserAuth
$aData = Utils::GetSecureCookie(self::AUTH_SPEC_TOKEN_KEY);
if ($aData) {
$this->oMainAuthAccount = Account::NewInstanceFromTokenArray(
$this->oMainAuthAccount = MainAccount::NewInstanceFromTokenArray(
$this,
$aData,
$bThrowExceptionOnFalse
@ -233,11 +232,8 @@ trait UserAuth
return $this->oMainAuthAccount;
}
public function SetAuthToken(Account $oAccount): void
public function SetAuthToken(MainAccount $oAccount): void
{
if (\is_subclass_of($oAccount, 'RainLoop\\Model\\Account')) {
throw new \LogicException('Only main Account can be set as AuthToken');
}
$this->oAdditionalAuthAccount = false;
$this->oMainAuthAccount = $oAccount;
Utils::SetSecureCookie(self::AUTH_SPEC_TOKEN_KEY, $oAccount);
@ -270,7 +266,7 @@ trait UserAuth
return null;
}
private function SetSignMeToken(Account $oAccount): void
private function SetSignMeToken(MainAccount $oAccount): void
{
$this->ClearSignMeData();
@ -295,7 +291,7 @@ trait UserAuth
);
}
public function GetAccountFromSignMeToken(): ?Account
public function GetAccountFromSignMeToken(): ?MainAccount
{
$aTokenData = static::GetSignMeToken();
if ($aTokenData) {
@ -314,7 +310,7 @@ trait UserAuth
]);
$oAccount = \is_array($aAccountHash)
? Account::NewInstanceFromTokenArray($this, $aAccountHash) : null;
? MainAccount::NewInstanceFromTokenArray($this, $aAccountHash) : null;
if ($oAccount) {
$this->CheckMailConnection($oAccount);
// Update lifetime

View file

@ -5,7 +5,7 @@ namespace RainLoop\Model;
use RainLoop\Utils;
use RainLoop\Exceptions\ClientException;
class Account implements \JsonSerializable
abstract class Account implements \JsonSerializable
{
/**
* @var string
@ -42,11 +42,6 @@ class Account implements \JsonSerializable
*/
private $oDomain;
/**
* @var string
*/
private $sCryptKey;
public function Email() : string
{
return $this->sEmail;
@ -99,14 +94,6 @@ class Account implements \JsonSerializable
return $this->IncPassword();
}
public function CryptKey() : string
{
if (!$this->sCryptKey) {
$this->SetCryptKey($this->IncPassword() ?: APP_SALT);
}
return $this->sCryptKey;
}
public function ClientCert() : string
{
return $this->sClientCert;
@ -132,11 +119,6 @@ class Account implements \JsonSerializable
$this->sPassword = $sPassword;
}
public function SetCryptKey(string $sKey) : void
{
$this->sCryptKey = \sha1($sKey, true);
}
public function SetProxyAuthUser(string $sProxyAuthUser) : void
{
$this->sProxyAuthUser = $sProxyAuthUser;

View file

@ -22,11 +22,6 @@ class AdditionalAccount extends Account
$this->sParentEmail = \trim(\MailSo\Base\Utils::IdnToAscii($sParentEmail, true));
}
public function CryptKey() : string
{
throw new \LogicException('Not allowed on AdditionalAccount');
}
public function Hash() : string
{
return \md5(parent::Hash() . $this->sParentEmail);
@ -39,7 +34,7 @@ class AdditionalAccount extends Account
return $aData;
}
public function asTokenArray(Account $oMainAccount) : array
public function asTokenArray(MainAccount $oMainAccount) : array
{
$sHash = $oMainAccount->CryptKey();
$aData = $this->jsonSerialize();

View file

@ -0,0 +1,27 @@
<?php
namespace RainLoop\Model;
use RainLoop\Utils;
use RainLoop\Exceptions\ClientException;
class MainAccount extends Account
{
/**
* @var string
*/
private $sCryptKey;
public function CryptKey() : string
{
if (!$this->sCryptKey) {
$this->SetCryptKey($this->IncPassword() ?: APP_SALT);
}
return $this->sCryptKey;
}
public function SetCryptKey(string $sKey) : void
{
$this->sCryptKey = \sha1($sKey, true);
}
}

View file

@ -27,8 +27,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array
{
$aSuggestions = array();
if ($oAccount instanceof \RainLoop\Model\Account &&
$this->IsActive() && \is_array($this->aDrivers) && 0 < \strlen($sQuery))
if ($this->IsActive() && \is_array($this->aDrivers) && 0 < \strlen($sQuery))
{
foreach ($this->aDrivers as $oDriver)
{