2020-09-21 01:19:12 +02:00
|
|
|
const appUtilities = (app) => {
|
2019-09-25 20:32:52 +02:00
|
|
|
app.getSettingsItem = settingsKey => {
|
2020-09-22 04:49:02 +02:00
|
|
|
let savedSettings = app.state.isFrontend && window.localStorage.getItem('settings');
|
2019-09-25 20:32:52 +02:00
|
|
|
if (savedSettings) {
|
|
|
|
savedSettings = JSON.parse(savedSettings);
|
|
|
|
if (typeof savedSettings[settingsKey] !== 'undefined') {
|
|
|
|
return savedSettings[settingsKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
app.setSettingsItem = (settingsKey, value) => {
|
2020-09-22 04:49:02 +02:00
|
|
|
if (!app.state.isFrontend) return null;
|
2020-09-21 01:19:12 +02:00
|
|
|
|
2019-09-25 20:32:52 +02:00
|
|
|
let savedSettings = window.localStorage.getItem('settings');
|
|
|
|
if (savedSettings) {
|
|
|
|
savedSettings = JSON.parse(savedSettings);
|
|
|
|
} else {
|
|
|
|
savedSettings = {};
|
|
|
|
}
|
|
|
|
savedSettings[settingsKey] = value;
|
|
|
|
return window.localStorage.setItem('settings', JSON.stringify(savedSettings));
|
|
|
|
}
|
2019-10-18 05:35:32 +02:00
|
|
|
|
|
|
|
app.checkIfLoggedIn = (appState) => {
|
2020-09-22 04:49:02 +02:00
|
|
|
if (!app.state.isFrontend) return false;
|
|
|
|
|
2019-10-18 05:35:32 +02:00
|
|
|
return fetch('/api/account/validate', { method: 'post' })
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(response => {
|
|
|
|
if (response.error !== false) {
|
2019-12-01 22:08:12 +01:00
|
|
|
console.warn(appState.i18n.__(response.message));
|
2019-10-18 05:35:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-01 22:08:12 +01:00
|
|
|
console.info(appState.i18n.__(response.message));
|
2019-10-18 05:35:32 +02:00
|
|
|
appState.isLoggedIn = true;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2020-09-21 01:19:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { appUtilities };
|