Keep AUTH_SPEC_TOKEN_KEY

And now we can embed theme and language in index.html template
This commit is contained in:
djmaze 2021-04-28 12:08:07 +02:00
parent 4579a786ab
commit ce63ba506a
7 changed files with 30 additions and 49 deletions

View file

@ -3,7 +3,7 @@ import { Notification, UploadErrorCode } from 'Common/Enums';
import { langLink } from 'Common/Links';
import { doc, createElement } from 'Common/Globals';
let I18N_DATA = window.snappymailI18N || {};
let I18N_DATA = {};
export const trigger = ko.observable(false);
@ -49,10 +49,21 @@ const i18nToNode = element => {
}
},
init = () => {
if (rl.I18N) {
I18N_DATA = rl.I18N;
Date.defineRelativeTimeFormat(rl.relativeTime || {});
rl.I18N = null;
return 1;
}
},
i18nKey = key => key.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase(),
getKeyByValue = (o, v) => Object.keys(o).find(key => o[key] === v);
init();
/**
* @param {Object} elements
* @param {boolean=} animate = false
@ -127,13 +138,11 @@ export function reload(admin, language) {
const script = createElement('script');
script.onload = () => {
// reload the data
if (window.snappymailI18N) {
I18N_DATA = window.snappymailI18N;
if (init()) {
i18nToNodes(doc);
dispatchEvent(new CustomEvent('reload-time'));
trigger(!trigger());
}
window.snappymailI18N = null;
script.remove();
resolve();
};

View file

@ -1,5 +1,5 @@
import { SaveSettingsStep } from 'Common/Enums';
import { doc, createElement, elementById } from 'Common/Globals';
import { doc, elementById } from 'Common/Globals';
export const
isArray = Array.isArray,
@ -84,14 +84,13 @@ let __themeTimer = 0,
* @returns {void}
*/
export function changeTheme(value, themeTrigger = ()=>{}) {
const themeLink = elementById('app-theme-link'),
const themeStyle = elementById('app-theme-style'),
clearTimer = () => {
__themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
__themeJson = null;
};
let themeStyle = elementById('app-theme-style'),
url = (themeLink && themeLink.href) || (themeStyle && themeStyle.dataset.href);
let url = themeStyle.dataset.href;
if (url) {
url = url.toString()
@ -118,19 +117,9 @@ export function changeTheme(value, themeTrigger = ()=>{}) {
rl.fetchJSON(url, init)
.then(data => {
if (data && isArray(data) && 2 === data.length) {
if (themeLink && !themeStyle) {
themeStyle = createElement('style');
themeStyle.id = 'app-theme-style';
themeLink.after(themeStyle);
themeLink.remove();
}
if (themeStyle) {
themeStyle.textContent = data[1];
themeStyle.dataset.href = url;
themeStyle.dataset.theme = data[0];
}
themeStyle.textContent = data[1];
themeStyle.dataset.href = url;
themeStyle.dataset.theme = data[0];
themeTrigger(SaveSettingsStep.TrueResult);
}
})

View file

@ -144,12 +144,7 @@ win.rl = {
rl.hash.set();
if (appData) {
if (appData.NewThemeLink) {
eId('app-theme-link').href = appData.NewThemeLink;
}
loadScript(appData.StaticLibJsLink)
.then(() => loadScript(appData.LangLink))
.then(() => loadScript(appData.StaticAppJsLink))
.then(() => appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve())
.then(() => win.__APP_BOOT ? win.__APP_BOOT(showError) : showError())
@ -170,7 +165,7 @@ Storage('local');
// init section
setInterval(setTimestamp, 60000); // 1m
[eId('app-css'),eId('app-theme-link')].forEach(css => css.href = css.dataset.href);
eId('app-css').href = eId('app-css').dataset.href;
loadScript(`./?/${admin ? 'Admin' : ''}AppData/${rl.hash.get() || '0'}/${Math.random().toString().substr(2)}/`)
.then(() => {});

View file

@ -508,12 +508,7 @@ class Actions
public function GetSpecAuthTokenWithDeletion(): string
{
$sResult = Utils::GetCookie(self::AUTH_SPEC_TOKEN_KEY, '');
if (0 < strlen($sResult)) {
// TODO: Browser F5 issue
Utils::ClearCookie(self::AUTH_SPEC_TOKEN_KEY);
}
return $sResult;
return Utils::GetCookie(self::AUTH_SPEC_TOKEN_KEY, '');
}
public function GetSpecAuthLogoutTokenWithDeletion(): string
@ -1252,7 +1247,6 @@ class Actions
$sStaticCache = $this->StaticCache();
$aResult['Theme'] = $this->GetTheme($bAdmin);
$aResult['NewThemeLink'] = $this->ThemeLink($bAdmin);
$aResult['Language'] = $this->ValidateLanguage($sLanguage, '', false);
$aResult['UserLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true);
@ -1260,8 +1254,6 @@ class Actions
$aResult['LanguageAdmin'] = $this->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true);
$aResult['UserLanguageAdmin'] = $this->ValidateLanguage($UserLanguageRaw, '', true, true);
}
$aResult['LangLink'] = './?/Lang/0/' . ($bAdmin ? 'Admin' : 'App') . '/' .
($bAdmin ? $aResult['LanguageAdmin'] : $aResult['Language']) . '/' . $sStaticCache . '/';
$aResult['PluginsLink'] = '';
if (0 < $this->Plugins()->Count() && $this->Plugins()->HaveJs($bAdmin)) {

View file

@ -143,6 +143,6 @@ trait Localization
}
}
return "document.documentElement.lang = '{$sLanguage}';\nwindow.snappymailI18N={$sResult};\nDate.defineRelativeTimeFormat({$sTimeFormat});";
return "document.documentElement.lang = '{$sLanguage}';\nrl.I18N={$sResult};\nrl.relativeTime = {$sTimeFormat};";
}
}

View file

@ -158,26 +158,22 @@ class Service
return $this;
}
$aTemplateParameters = $this->indexTemplateParameters($bAdmin);
$this->oServiceActions->getAuthAccountHash($bAdmin);
$sLanguage = $this->oActions->GetLanguage($bAdmin);
// TODO: Browser F5 issue
// $this->oServiceActions->getAuthAccountHash($bAdmin);
// $sLanguage = $this->oActions->GetLanguage($bAdmin);
$aTemplateParameters = $this->indexTemplateParameters($bAdmin);
$sCacheFileName = '';
if ($this->oActions->Config()->Get('labs', 'cache_system_data', true) && !empty($aTemplateParameters['{{BaseHash}}']))
{
// TODO: Browser F5 issue
// $sCacheFileName = 'TMPL:'.$sLanguage.$aTemplateParameters['{{BaseHash}}'];
$sCacheFileName = 'TMPL:'.$aTemplateParameters['{{BaseHash}}'];
$sCacheFileName = 'TMPL:'.$sLanguage.$aTemplateParameters['{{BaseHash}}'];
$sResult = $this->oActions->Cacher()->Get($sCacheFileName);
}
if (0 === \strlen($sResult))
{
// $aTemplateParameters['{{BaseAppThemeCss}}'] = $this->oServiceActions->compileCss($this->oActions->GetTheme($bAdmin));
// TODO: Browser F5 issue
// $aTemplateParameters['{{BaseLanguage}}'] = $this->oServiceActions->compileLanguage($sLanguage, $bAdmin);
$aTemplateParameters['{{BaseAppThemeCss}}'] = $this->oActions->compileCss($this->oActions->GetTheme($bAdmin), $bAdmin);
$aTemplateParameters['{{BaseLanguage}}'] = $this->oActions->compileLanguage($sLanguage, $bAdmin);
$aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false);
$sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), $aTemplateParameters);

View file

@ -13,8 +13,8 @@
<title></title>
<style id="app-boot-css">{{BaseAppBootCss}}</style>
<link type="text/css" rel="stylesheet" data-href="{{BaseAppMainCssLink}}" id="app-css" rel="preload">
<link type="text/css" rel="stylesheet" data-href="{{BaseAppThemeCssLink}}" id="app-theme-link" rel="preload">
<link rel="manifest" href="{{BaseAppManifestLink}}">
<style id="app-theme-style" data-href="{{BaseAppThemeCssLink}}">{{BaseAppThemeCss}}</style>
<script>document.append||document.location.replace('./?/BadBrowser');</script>
{{BaseAppFaviconPngLinkTag}}
{{BaseAppFaviconTouchLinkTag}}
@ -40,8 +40,8 @@
</div>
</div>
<div id="progressjs"><div></div></div>
<script type="text/javascript">{{BaseAppBootScript}}{{BaseLanguage}}</script>
{{BaseTemplates}}
<script type="text/javascript">{{BaseAppBootScript}}{{BaseLanguage}}</script>
</body>
</html>