diff --git a/dev/Remote/User/Fetch.js b/dev/Remote/User/Fetch.js index 29a7f048f..ee7f781cd 100644 --- a/dev/Remote/User/Fetch.js +++ b/dev/Remote/User/Fetch.js @@ -56,6 +56,13 @@ class RemoteUserFetch extends AbstractFetchRemote { this.defaultRequest(fCallback, 'Login', oData); } +/* + // TODO SystemDropDownUserView.accountClick + switchAccount(fCallback, email) { + this.defaultRequest(fCallback, 'AccountSwitch', {Email:email}); + } +*/ + /** * @param {?Function} fCallback */ diff --git a/dev/View/User/SystemDropDown.js b/dev/View/User/SystemDropDown.js index bcf4de763..9e0a71141 100644 --- a/dev/View/User/SystemDropDown.js +++ b/dev/View/User/SystemDropDown.js @@ -16,6 +16,8 @@ import { doc, Settings, leftPanelDisabled } from 'Common/Globals'; import { ThemeStore } from 'Stores/Theme'; +//import Remote from 'Remote/User/Fetch'; + export class SystemDropDownUserView extends AbstractViewRight { constructor() { super('SystemDropDown'); @@ -44,11 +46,28 @@ export class SystemDropDownUserView extends AbstractViewRight { } accountClick(account, event) { +/* TODO + event.preventDefault(); + event.stopPropagation(); + Remote.switchAccount( + (iError, oData) => { + if (iError) { + console.dir({ + iError: iError, + oData: oData + }) + } else { + rl.setData(oData.Result); +// rl.route.reload(); + } + }, + account.email + ); +*/ if (account && 0 === event.button) { AccountUserStore.loading(true); setTimeout(() => AccountUserStore.loading(false), 1000); } - return true; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php index 40316a8fd..57e2bc38d 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php @@ -200,6 +200,17 @@ trait Accounts return $this->FalseResponse(__FUNCTION__); } + /** + * @throws \MailSo\Base\Exceptions\Exception + */ + public function DoAccountSwitch(): array + { + if ($this->switchAccount(\trim($this->GetActionParam('Email', '')))) { + return $this->DefaultResponse(__FUNCTION__, $this->AppData(false)); + } + return $this->FalseResponse(__FUNCTION__); + } + /** * @throws \MailSo\Base\Exceptions\Exception */ 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 59a8b0189..0f537f95a 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 @@ -143,6 +143,26 @@ trait UserAuth return $oAccount; } + public function switchAccount(string $sEmail) : bool + { + $this->Http()->ServerNoCache(); + $oMainAccount = $this->getMainAccountFromToken(false); + if ($sEmail && $oMainAccount && $this->GetCapa(false, \RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS, $oMainAccount)) { + $oAccountToLogin = null; + $sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail); + $aAccounts = $this->GetAccounts($oMainAccount); + if (isset($aAccounts[$sEmail])) { + $oAccountToLogin = \RainLoop\Model\AdditionalAccount::NewInstanceFromTokenArray( + $this, + $aAccounts[$sEmail] + ); + } + $this->SetAdditionalAuthToken($oAccountToLogin); + return true; + } + return false; + } + /** * Returns RainLoop\Model\AdditionalAccount when it exists, * else returns RainLoop\Model\Account when it exists, diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php index 7a4f7b4b0..ac90f4e4f 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php @@ -201,9 +201,9 @@ class Account implements \JsonSerializable if (!empty($aAccountHash[0]) && 'account' === $aAccountHash[0] && 7 === \count($aAccountHash)) { $oAccount = static::NewInstanceByLogin( $oActions, - $aAccountHash[1], - $aAccountHash[2], - $aAccountHash[3], + $aAccountHash[1] ?: '', + $aAccountHash[2] ?: '', + $aAccountHash[3] ?: '', $aAccountHash[4] ?: '', $bThrowExceptionOnFalse ); 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 110ce806a..94c111054 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -816,30 +816,9 @@ class ServiceActions */ public function ServiceChange() : string { - $this->oHttp->ServerNoCache(); - - $oMainAccount = $this->oActions->getMainAccountFromToken(false); - - if ($oMainAccount && $this->oActions->GetCapa(false, Enumerations\Capa::ADDITIONAL_ACCOUNTS, $oMainAccount)) - { - $oAccountToLogin = null; - $sEmail = empty($this->aPaths[2]) ? '' : \urldecode(\trim($this->aPaths[2])); - if (!empty($sEmail)) - { - $sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail); - - $aAccounts = $this->oActions->GetAccounts($oMainAccount); - if (isset($aAccounts[$sEmail])) - { - $oAccountToLogin = \RainLoop\Model\AdditionalAccount::NewInstanceFromTokenArray( - $this->oActions, - $aAccounts[$sEmail] - ); - } - } - $this->oActions->SetAdditionalAuthToken($oAccountToLogin); - } - + $oMainAccount = $this->oActions->switchAccount( + empty($this->aPaths[2]) ? '' : \urldecode(\trim($this->aPaths[2])) + ); $this->oActions->Location('./'); return ''; } @@ -849,7 +828,7 @@ class ServiceActions */ public function ErrorTemplates(string $sTitle, string $sDesc, bool $bShowBackLink = true) { - return strtr(file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Error.html'), array( + return \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Error.html'), array( '{{BaseWebStaticPath}}' => Utils::WebStaticPath(), '{{ErrorTitle}}' => $sTitle, '{{ErrorHeader}}' => $sTitle, @@ -862,7 +841,7 @@ class ServiceActions private function localError(string $sTitle, string $sDesc) : string { - header('Content-Type: text/html; charset=utf-8'); + \header('Content-Type: text/html; charset=utf-8'); return $this->ErrorTemplates($sTitle, \nl2br($sDesc)); } diff --git a/snappymail/v/0.0.0/include.php b/snappymail/v/0.0.0/include.php index 3e2813f07..7f94e9c3c 100644 --- a/snappymail/v/0.0.0/include.php +++ b/snappymail/v/0.0.0/include.php @@ -69,7 +69,7 @@ if (defined('APP_VERSION')) define('APP_DATA_FOLDER_PATH_UNIX', str_replace('\\', '/', APP_DATA_FOLDER_PATH)); - $sSalt = is_file(APP_DATA_FOLDER_PATH.'SALT.php') ? file_get_contents(APP_DATA_FOLDER_PATH.'SALT.php') : ''; + $sSalt = is_file(APP_DATA_FOLDER_PATH.'SALT.php') ? trim(file_get_contents(APP_DATA_FOLDER_PATH.'SALT.php')) : ''; $sData = is_file(APP_DATA_FOLDER_PATH.'DATA.php') ? file_get_contents(APP_DATA_FOLDER_PATH.'DATA.php') : ''; $sInstalled = is_file(APP_DATA_FOLDER_PATH.'INSTALLED') ? file_get_contents(APP_DATA_FOLDER_PATH.'INSTALLED') : '';