[FIX] Forget user session on window close (#15205)

pull/15214/head
Guilherme Gazzo 6 years ago committed by Diego Sampaio
parent d62842642d
commit f7ce6ac0dd
  1. 2
      app/channel-settings-mail-messages/client/views/mailMessagesInstructions.js
  2. 3
      app/e2e/client/accountEncryption.js
  3. 34
      app/e2e/client/rocketchat.e2e.js
  4. 11
      app/emoji/client/lib/EmojiPicker.js
  5. 2
      app/oauth2-server-config/client/oauth/oauth2-client.js
  6. 6
      app/setup-wizard/client/final.js
  7. 10
      app/setup-wizard/client/setupWizard.js
  8. 10
      app/ui-account/client/accountPreferences.js
  9. 3
      app/ui-login/client/login/footer.js
  10. 18
      app/ui-master/server/inject.js
  11. 4
      app/ui-utils/client/config.js
  12. 3
      app/ui-utils/client/lib/menu.js
  13. 5
      app/ui-utils/lib/Message.js
  14. 8
      app/ui/client/lib/chatMessages.js
  15. 9
      app/utils/client/lib/RestApiClient.js
  16. 3
      app/utils/lib/tapi18n.js
  17. 4
      client/startup/i18n.js

@ -129,7 +129,7 @@ Template.mailMessagesInstructions.events({
to_emails: selectedEmails.get().map((email) => email.text).toString(),
subject,
messages: selectedMessages.get(),
language: localStorage.getItem('userLanguage'),
language: Meteor._localStorage.getItem('userLanguage'),
};
Meteor.call('mailMessages', data, function(err, result) {

@ -1,4 +1,5 @@
import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import toastr from 'toastr';
import s from 'underscore.string';
@ -12,7 +13,7 @@ Template.accountEncryption.helpers({
return settings.get('E2E_Enable');
},
allowKeyChange() {
return localStorage.getItem('public_key') && localStorage.getItem('private_key');
return Meteor._localStorage.getItem('public_key') && Meteor._localStorage.getItem('private_key');
},
canConfirmNewKey() {
const encryptionKey = Template.instance().encryptionKey.get();

@ -104,8 +104,8 @@ class E2E {
}
this.started = true;
let public_key = localStorage.getItem('public_key');
let private_key = localStorage.getItem('private_key');
let public_key = Meteor._localStorage.getItem('public_key');
let private_key = Meteor._localStorage.getItem('private_key');
await this.loadKeysFromDB();
@ -143,12 +143,12 @@ class E2E {
// TODO: Split in 2 methods to persist keys
if (!this.db_public_key || !this.db_private_key) {
await call('e2e.setUserPublicAndPivateKeys', {
public_key: localStorage.getItem('public_key'),
private_key: await this.encodePrivateKey(localStorage.getItem('private_key'), this.createRandomPassword()),
public_key: Meteor._localStorage.getItem('public_key'),
private_key: await this.encodePrivateKey(Meteor._localStorage.getItem('private_key'), this.createRandomPassword()),
});
}
const randomPassword = localStorage.getItem('e2e.randomPassword');
const randomPassword = Meteor._localStorage.getItem('e2e.randomPassword');
if (randomPassword) {
const passwordRevealText = TAPi18n.__('E2E_password_reveal_text', {
postProcess: 'sprintf',
@ -174,7 +174,7 @@ class E2E {
if (!confirm) {
return;
}
localStorage.removeItem('e2e.randomPassword');
Meteor._localStorage.removeItem('e2e.randomPassword');
this.closeAlert();
});
},
@ -196,8 +196,8 @@ class E2E {
alerts.close();
}
localStorage.removeItem('public_key');
localStorage.removeItem('private_key');
Meteor._localStorage.removeItem('public_key');
Meteor._localStorage.removeItem('private_key');
this.instancesByRoomId = {};
this.privateKey = null;
this.enabled.set(false);
@ -233,12 +233,12 @@ class E2E {
async changePassword(newPassword) {
await call('e2e.setUserPublicAndPivateKeys', {
public_key: localStorage.getItem('public_key'),
private_key: await this.encodePrivateKey(localStorage.getItem('private_key'), newPassword),
public_key: Meteor._localStorage.getItem('public_key'),
private_key: await this.encodePrivateKey(Meteor._localStorage.getItem('private_key'), newPassword),
});
if (localStorage.getItem('e2e.randomPassword')) {
localStorage.setItem('e2e.randomPassword', newPassword);
if (Meteor._localStorage.getItem('e2e.randomPassword')) {
Meteor._localStorage.setItem('e2e.randomPassword', newPassword);
}
}
@ -254,12 +254,12 @@ class E2E {
}
async loadKeys({ public_key, private_key }) {
localStorage.setItem('public_key', public_key);
Meteor._localStorage.setItem('public_key', public_key);
try {
this.privateKey = await importRSAKey(EJSON.parse(private_key), ['decrypt']);
localStorage.setItem('private_key', private_key);
Meteor._localStorage.setItem('private_key', private_key);
} catch (error) {
return console.error('E2E -> Error importing private key: ', error);
}
@ -278,7 +278,7 @@ class E2E {
try {
const publicKey = await exportJWKKey(key.publicKey);
localStorage.setItem('public_key', JSON.stringify(publicKey));
Meteor._localStorage.setItem('public_key', JSON.stringify(publicKey));
} catch (error) {
return console.error('E2E -> Error exporting public key: ', error);
}
@ -286,7 +286,7 @@ class E2E {
try {
const privateKey = await exportJWKKey(key.privateKey);
localStorage.setItem('private_key', JSON.stringify(privateKey));
Meteor._localStorage.setItem('private_key', JSON.stringify(privateKey));
} catch (error) {
return console.error('E2E -> Error exporting private key: ', error);
}
@ -300,7 +300,7 @@ class E2E {
createRandomPassword() {
const randomPassword = `${ Random.id(3) }-${ Random.id(3) }-${ Random.id(3) }`.toLowerCase();
localStorage.setItem('e2e.randomPassword', randomPassword);
Meteor._localStorage.setItem('e2e.randomPassword', randomPassword);
return randomPassword;
}

@ -1,5 +1,6 @@
import _ from 'underscore';
import { Blaze } from 'meteor/blaze';
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
@ -27,8 +28,8 @@ export const EmojiPicker = {
}
this.initiated = true;
this.recent = window.localStorage.getItem('emoji.recent') ? window.localStorage.getItem('emoji.recent').split(',') : [];
this.tone = window.localStorage.getItem('emoji.tone') || 0;
this.recent = Meteor._localStorage.getItem('emoji.recent') ? Meteor._localStorage.getItem('emoji.recent').split(',') : [];
this.tone = Meteor._localStorage.getItem('emoji.tone') || 0;
Blaze.render(Template.emojiPicker, document.body);
@ -55,7 +56,7 @@ export const EmojiPicker = {
},
setTone(tone) {
this.tone = tone;
window.localStorage.setItem('emoji.tone', tone);
Meteor._localStorage.setItem('emoji.tone', tone);
},
getTone() {
return this.tone;
@ -130,7 +131,7 @@ export const EmojiPicker = {
updatePositions = true;
window.localStorage.setItem('emoji.recent', this.recent);
Meteor._localStorage.setItem('emoji.recent', this.recent);
emoji.packages.base.emojisByCategory.recent = this.recent;
this.updateRecent('recent');
},
@ -140,7 +141,7 @@ export const EmojiPicker = {
return;
}
this.recent.splice(pos, 1);
window.localStorage.setItem('emoji.recent', this.recent);
Meteor._localStorage.setItem('emoji.recent', this.recent);
},
updateRecent(category) {
updateRecentEmoji(category);

@ -36,7 +36,7 @@ Template.authorize.onCreated(function() {
Template.authorize.helpers({
getToken() {
return localStorage.getItem(Accounts.LOGIN_TOKEN_KEY);
return Meteor._localStorage.getItem(Accounts.LOGIN_TOKEN_KEY);
},
getClient() {
return ChatOAuthApps.findOne();

@ -7,7 +7,7 @@ import { Users } from '../../models';
import { hasRole } from '../../authorization';
Template.setupWizardFinal.onCreated(function() {
const isSetupWizardDone = localStorage.getItem('wizardFinal');
const isSetupWizardDone = Meteor._localStorage.getItem('wizardFinal');
if (isSetupWizardDone === null) {
FlowRouter.go('setup-wizard');
}
@ -44,8 +44,8 @@ Template.setupWizardFinal.onRendered(function() {
Template.setupWizardFinal.events({
'click .js-finish'() {
settings.set('Show_Setup_Wizard', 'completed', function() {
localStorage.removeItem('wizard');
localStorage.removeItem('wizardFinal');
Meteor._localStorage.removeItem('wizard');
Meteor._localStorage.removeItem('wizardFinal');
FlowRouter.go('home');
});
},

@ -112,11 +112,11 @@ Template.setupWizard.onCreated(async function() {
this.wizardSettings = new ReactiveVar([]);
this.allowStandaloneServer = new ReactiveVar(false);
if (localStorage.getItem('wizardFinal')) {
if (Meteor._localStorage.getItem('wizardFinal')) {
return FlowRouter.go('setup-wizard-final');
}
const jsonString = localStorage.getItem('wizard');
const jsonString = Meteor._localStorage.getItem('wizard');
const state = (jsonString && JSON.parse(jsonString)) || statusDefault;
this.state.set(state);
@ -132,7 +132,7 @@ Template.setupWizard.onCreated(async function() {
this.autorun(() => {
const state = this.state.all();
state['registration-pass'] = '';
localStorage.setItem('wizard', JSON.stringify(state));
Meteor._localStorage.setItem('wizard', JSON.stringify(state));
});
this.autorun(async (c) => {
@ -196,8 +196,8 @@ Template.setupWizard.events({
}
case 4: {
persistSettings(t.state.all(), () => {
localStorage.removeItem('wizard');
localStorage.setItem('wizardFinal', true);
Meteor._localStorage.removeItem('wizard');
Meteor._localStorage.setItem('wizardFinal', true);
if (t.state.get('registerServer')) {
Meteor.call('cloud:registerWorkspace', (error) => {

@ -138,11 +138,11 @@ Template.accountPreferences.onCreated(function() {
});
this.clearForm = function() {
this.find('#language').value = localStorage.getItem('userLanguage');
this.find('#language').value = Meteor._localStorage.getItem('userLanguage');
};
this.shouldUpdateLocalStorageSetting = function(setting, newValue) {
return localStorage.getItem(setting) !== newValue;
return Meteor._localStorage.getItem(setting) !== newValue;
};
this.save = function() {
@ -190,7 +190,7 @@ Template.accountPreferences.onCreated(function() {
const selectedLanguage = $('#language').val();
if (this.shouldUpdateLocalStorageSetting('userLanguage', selectedLanguage)) {
localStorage.setItem('userLanguage', selectedLanguage);
Meteor._localStorage.setItem('userLanguage', selectedLanguage);
data.language = selectedLanguage;
reload = true;
}
@ -198,14 +198,14 @@ Template.accountPreferences.onCreated(function() {
const enableAutoAway = JSON.parse($('#enableAutoAway').find('input:checked').val());
data.enableAutoAway = enableAutoAway;
if (this.shouldUpdateLocalStorageSetting('enableAutoAway', enableAutoAway)) {
localStorage.setItem('enableAutoAway', enableAutoAway);
Meteor._localStorage.setItem('enableAutoAway', enableAutoAway);
reload = true;
}
const idleTimeLimit = $('input[name=idleTimeLimit]').val() === '' ? settings.get('Accounts_Default_User_Preferences_idleTimeLimit') : parseInt($('input[name=idleTimeLimit]').val());
data.idleTimeLimit = idleTimeLimit;
if (this.shouldUpdateLocalStorageSetting('idleTimeLimit', idleTimeLimit)) {
localStorage.setItem('idleTimeLimit', idleTimeLimit);
Meteor._localStorage.setItem('idleTimeLimit', idleTimeLimit);
reload = true;
}

@ -1,4 +1,5 @@
import { ReactiveVar } from 'meteor/reactive-var';
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
@ -22,7 +23,7 @@ Template.loginFooter.onCreated(function() {
}
};
const currentLanguage = localStorage.getItem('userLanguage');
const currentLanguage = Meteor._localStorage.getItem('userLanguage');
this.suggestAnotherLanguageFor(currentLanguage);
});

@ -170,13 +170,19 @@ settings.get('Accounts_ForgetUserSessionOnWindowClose', (key, value) => {
if (value) {
Inject.rawModHtml(key, (html) => {
const script = `
<script>
if (Meteor._localStorage._data === undefined && window.sessionStorage) {
Meteor._localStorage = window.sessionStorage;
}
</script>
<script>
window.addEventListener('load', function() {
if (window.localStorage) {
Object.keys(window.localStorage).forEach(function(key) {
window.sessionStorage.setItem(key, window.localStorage.getItem(key));
});
window.localStorage.clear();
Meteor._localStorage = window.sessionStorage;
}
});
</script>
`;
return html.replace(/<\/body>/, `${ script }\n</body>`);
return html + script;
});
} else {
Inject.rawModHtml(key, (html) => html);

@ -1,6 +1,8 @@
import { Meteor } from 'meteor/meteor';
const url = new URL(window.location);
const keys = new Set();
export const getConfig = (key) => {
keys.add(key);
return url.searchParams.get(key) || localStorage.getItem(`rc-config-${ key }`);
return url.searchParams.get(key) || Meteor._localStorage.getItem(`rc-config-${ key }`);
};

@ -1,4 +1,5 @@
import { Session } from 'meteor/session';
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';
import EventEmitter from 'wolfy87-eventemitter';
@ -42,7 +43,7 @@ export const menu = new class extends EventEmitter {
}
get isRtl() {
return isRtl(localStorage.getItem('userLanguage'));
return isRtl(Meteor._localStorage.getItem('userLanguage'));
}
touchstart(e) {

@ -1,4 +1,5 @@
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Meteor } from 'meteor/meteor';
import s from 'underscore.string';
import { MessageTypes } from './MessageTypes';
@ -14,8 +15,8 @@ export const Message = {
// Render message
return;
} if (messageType.message) {
if (!language && typeof localStorage !== 'undefined') {
language = localStorage.getItem('userLanguage');
if (!language) {
language = Meteor._localStorage.getItem('userLanguage');
}
const data = (typeof messageType.data === 'function' && messageType.data(msg)) || {};
return TAPi18n.__(messageType.message, data, language);

@ -32,12 +32,12 @@ import { emoji } from '../../../emoji/client';
const messageBoxState = {
saveValue: _.debounce(({ rid, tmid }, value) => {
const key = ['messagebox', rid, tmid].filter(Boolean).join('_');
value ? localStorage.setItem(key, value) : localStorage.removeItem(key);
value ? Meteor._localStorage.setItem(key, value) : Meteor._localStorage.removeItem(key);
}, 1000),
restoreValue: ({ rid, tmid }) => {
const key = ['messagebox', rid, tmid].filter(Boolean).join('_');
return localStorage.getItem(key);
return Meteor._localStorage.getItem(key);
},
restore: ({ rid, tmid }, input) => {
@ -57,9 +57,9 @@ const messageBoxState = {
},
purgeAll: () => {
Object.keys(localStorage)
Object.keys(Meteor._localStorage)
.filter((key) => key.indexOf('messagebox_') === 0)
.forEach((key) => localStorage.removeItem(key));
.forEach((key) => Meteor._localStorage.removeItem(key));
},
};

@ -1,3 +1,4 @@
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
export const APIClient = {
@ -49,8 +50,8 @@ export const APIClient = {
url: `${ document.baseURI }api/${ endpoint }${ query }`,
headers: {
'Content-Type': 'application/json',
'X-User-Id': localStorage[Accounts.USER_ID_KEY],
'X-Auth-Token': localStorage[Accounts.LOGIN_TOKEN_KEY],
'X-User-Id': Meteor._localStorage.getItem(Accounts.USER_ID_KEY),
'X-Auth-Token': Meteor._localStorage.getItem(Accounts.LOGIN_TOKEN_KEY),
},
data: JSON.stringify(body),
success: function _rlGetSuccess(result) {
@ -76,8 +77,8 @@ export const APIClient = {
jQuery.ajax({
url: `${ document.baseURI }api/${ endpoint }${ query }`,
headers: {
'X-User-Id': localStorage[Accounts.USER_ID_KEY],
'X-Auth-Token': localStorage[Accounts.LOGIN_TOKEN_KEY],
'X-User-Id': Meteor._localStorage.getItem(Accounts.USER_ID_KEY),
'X-Auth-Token': Meteor._localStorage.getItem(Accounts.LOGIN_TOKEN_KEY),
},
data: formData,
processData: false,

@ -1,5 +1,6 @@
import _ from 'underscore';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Meteor } from 'meteor/meteor';
export const t = function(key, ...replaces) {
if (_.isObject(replaces[0])) {
@ -12,6 +13,6 @@ export const t = function(key, ...replaces) {
};
export const isRtl = (lang) => {
const language = lang || localStorage.getItem('userLanguage') || 'en-US';
const language = lang || Meteor._localStorage.getItem('userLanguage') || 'en-US';
return ['ar', 'dv', 'fa', 'he', 'ku', 'ps', 'sd', 'ug', 'ur', 'yi'].includes(language.split('-').shift().toLowerCase());
};

@ -12,7 +12,7 @@ const currentLanguage = new ReactiveVar();
Meteor.startup(() => {
TAPi18n.conf.i18n_files_route = Meteor._relativeToSiteRootUrl('/tap-i18n');
currentLanguage.set(localStorage.getItem('userLanguage'));
currentLanguage.set(Meteor._localStorage.getItem('userLanguage'));
const availableLanguages = TAPi18n.getLanguages();
@ -70,7 +70,7 @@ Meteor.startup(() => {
const setLanguage = (language) => {
const lang = filterLanguage(language);
currentLanguage.set(lang);
localStorage.setItem('userLanguage', lang);
Meteor._localStorage.setItem('userLanguage', lang);
};
window.setLanguage = setLanguage;

Loading…
Cancel
Save