|
|
@ -9,6 +9,7 @@ define([
|
|
|
|
'/file/file-crypto.js',
|
|
|
|
'/file/file-crypto.js',
|
|
|
|
'/common/common-realtime.js',
|
|
|
|
'/common/common-realtime.js',
|
|
|
|
'/common/common-language.js',
|
|
|
|
'/common/common-language.js',
|
|
|
|
|
|
|
|
'/common/common-constants.js',
|
|
|
|
|
|
|
|
|
|
|
|
'/common/clipboard.js',
|
|
|
|
'/common/clipboard.js',
|
|
|
|
'/common/pinpad.js',
|
|
|
|
'/common/pinpad.js',
|
|
|
@ -17,7 +18,7 @@ define([
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
'/bower_components/localforage/dist/localforage.min.js',
|
|
|
|
'/bower_components/localforage/dist/localforage.min.js',
|
|
|
|
], function ($, Config, Messages, Store, Util, Hash,
|
|
|
|
], function ($, Config, Messages, Store, Util, Hash,
|
|
|
|
Messaging, FileCrypto, Realtime, Language, Clipboard,
|
|
|
|
Messaging, FileCrypto, Realtime, Language, Constants, Clipboard,
|
|
|
|
Pinpad, AppConfig, MediaTag, Nthen, localForage) {
|
|
|
|
Pinpad, AppConfig, MediaTag, Nthen, localForage) {
|
|
|
|
|
|
|
|
|
|
|
|
// Configure MediaTags to use our local viewer
|
|
|
|
// Configure MediaTags to use our local viewer
|
|
|
@ -42,14 +43,6 @@ define([
|
|
|
|
MediaTag: MediaTag,
|
|
|
|
MediaTag: MediaTag,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// constants
|
|
|
|
|
|
|
|
var userHashKey = common.userHashKey = 'User_hash';
|
|
|
|
|
|
|
|
var userNameKey = common.userNameKey = 'User_name';
|
|
|
|
|
|
|
|
var fileHashKey = common.fileHashKey = 'FS_hash';
|
|
|
|
|
|
|
|
common.displayNameKey = 'cryptpad.username';
|
|
|
|
|
|
|
|
var newPadPathKey = common.newPadPathKey = "newPadPath";
|
|
|
|
|
|
|
|
common.oldStorageKey = 'CryptPad_RECENTPADS';
|
|
|
|
|
|
|
|
common.storageKey = 'filesData';
|
|
|
|
|
|
|
|
var PINNING_ENABLED = AppConfig.enablePinning;
|
|
|
|
var PINNING_ENABLED = AppConfig.enablePinning;
|
|
|
|
|
|
|
|
|
|
|
|
var store;
|
|
|
|
var store;
|
|
|
@ -158,14 +151,14 @@ define([
|
|
|
|
common.getDisplayName = function (cb) {
|
|
|
|
common.getDisplayName = function (cb) {
|
|
|
|
var name;
|
|
|
|
var name;
|
|
|
|
if (getProxy()) {
|
|
|
|
if (getProxy()) {
|
|
|
|
name = getProxy()[common.displayNameKey];
|
|
|
|
name = getProxy()[Constants.displayNameKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
name = name || '';
|
|
|
|
name = name || '';
|
|
|
|
if (typeof cb === "function") { cb(null, name); }
|
|
|
|
if (typeof cb === "function") { cb(null, name); }
|
|
|
|
return name;
|
|
|
|
return name;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
common.getAccountName = function () {
|
|
|
|
common.getAccountName = function () {
|
|
|
|
return localStorage[common.userNameKey];
|
|
|
|
return localStorage[Constants.userNameKey];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// REFACTOR: move to util?
|
|
|
|
// REFACTOR: move to util?
|
|
|
@ -250,8 +243,8 @@ define([
|
|
|
|
if (!hash) { throw new Error('expected a user hash'); }
|
|
|
|
if (!hash) { throw new Error('expected a user hash'); }
|
|
|
|
if (!name) { throw new Error('expected a user name'); }
|
|
|
|
if (!name) { throw new Error('expected a user name'); }
|
|
|
|
hash = Hash.serializeHash(hash);
|
|
|
|
hash = Hash.serializeHash(hash);
|
|
|
|
localStorage.setItem(userHashKey, hash);
|
|
|
|
localStorage.setItem(Constants.userHashKey, hash);
|
|
|
|
localStorage.setItem(userNameKey, name);
|
|
|
|
localStorage.setItem(Constants.userNameKey, name);
|
|
|
|
if (cb) { cb(); }
|
|
|
|
if (cb) { cb(); }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -272,8 +265,8 @@ define([
|
|
|
|
var logoutHandlers = [];
|
|
|
|
var logoutHandlers = [];
|
|
|
|
common.logout = function (cb) {
|
|
|
|
common.logout = function (cb) {
|
|
|
|
[
|
|
|
|
[
|
|
|
|
userNameKey,
|
|
|
|
Constants.userNameKey,
|
|
|
|
userHashKey,
|
|
|
|
Constants.userHashKey,
|
|
|
|
'loginToken',
|
|
|
|
'loginToken',
|
|
|
|
'plan',
|
|
|
|
'plan',
|
|
|
|
].forEach(function (k) {
|
|
|
|
].forEach(function (k) {
|
|
|
@ -285,8 +278,8 @@ define([
|
|
|
|
localForage.clear();
|
|
|
|
localForage.clear();
|
|
|
|
// Make sure we have an FS_hash in localStorage before reloading all the tabs
|
|
|
|
// Make sure we have an FS_hash in localStorage before reloading all the tabs
|
|
|
|
// so that we don't end up with tabs using different anon hashes
|
|
|
|
// so that we don't end up with tabs using different anon hashes
|
|
|
|
if (!localStorage[fileHashKey]) {
|
|
|
|
if (!localStorage[Constants.fileHashKey]) {
|
|
|
|
localStorage[fileHashKey] = Hash.createRandomHash();
|
|
|
|
localStorage[Constants.fileHashKey] = Hash.createRandomHash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eraseTempSessionValues();
|
|
|
|
eraseTempSessionValues();
|
|
|
|
|
|
|
|
|
|
|
@ -303,16 +296,16 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var getUserHash = common.getUserHash = function () {
|
|
|
|
var getUserHash = common.getUserHash = function () {
|
|
|
|
var hash = localStorage[userHashKey];
|
|
|
|
var hash = localStorage[Constants.userHashKey];
|
|
|
|
|
|
|
|
|
|
|
|
if (['undefined', 'undefined/'].indexOf(hash) !== -1) {
|
|
|
|
if (['undefined', 'undefined/'].indexOf(hash) !== -1) {
|
|
|
|
localStorage.removeItem(userHashKey);
|
|
|
|
localStorage.removeItem(Constants.userHashKey);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (hash) {
|
|
|
|
if (hash) {
|
|
|
|
var sHash = Hash.serializeHash(hash);
|
|
|
|
var sHash = Hash.serializeHash(hash);
|
|
|
|
if (sHash !== hash) { localStorage[userHashKey] = sHash; }
|
|
|
|
if (sHash !== hash) { localStorage[Constants.userHashKey] = sHash; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
return hash;
|
|
|
@ -365,7 +358,7 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
common.setDisplayName = function (value, cb) {
|
|
|
|
common.setDisplayName = function (value, cb) {
|
|
|
|
if (getProxy()) {
|
|
|
|
if (getProxy()) {
|
|
|
|
getProxy()[common.displayNameKey] = value;
|
|
|
|
getProxy()[Constants.displayNameKey] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof cb === "function") { Realtime.whenRealtimeSyncs(getRealtime(), cb); }
|
|
|
|
if (typeof cb === "function") { Realtime.whenRealtimeSyncs(getRealtime(), cb); }
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -716,7 +709,7 @@ define([
|
|
|
|
var fo = proxy.fo;
|
|
|
|
var fo = proxy.fo;
|
|
|
|
|
|
|
|
|
|
|
|
// start with your userHash...
|
|
|
|
// start with your userHash...
|
|
|
|
var userHash = localStorage && localStorage.User_hash;
|
|
|
|
var userHash = localStorage && localStorage[Constants.userHashKey];
|
|
|
|
if (!userHash) { return null; }
|
|
|
|
if (!userHash) { return null; }
|
|
|
|
|
|
|
|
|
|
|
|
var userParsedHash = Hash.parseTypeHash('drive', userHash);
|
|
|
|
var userParsedHash = Hash.parseTypeHash('drive', userHash);
|
|
|
@ -1070,9 +1063,9 @@ define([
|
|
|
|
return void setTimeout(function () { f(void 0, env); });
|
|
|
|
return void setTimeout(function () { f(void 0, env); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sessionStorage[newPadPathKey]) {
|
|
|
|
if (sessionStorage[Constants.newPadPathKey]) {
|
|
|
|
common.initialPath = sessionStorage[newPadPathKey];
|
|
|
|
common.initialPath = sessionStorage[Constants.newPadPathKey];
|
|
|
|
delete sessionStorage[newPadPathKey];
|
|
|
|
delete sessionStorage[Constants.newPadPathKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var proxy;
|
|
|
|
var proxy;
|
|
|
@ -1138,7 +1131,7 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// Listen for login/logout in other tabs
|
|
|
|
// Listen for login/logout in other tabs
|
|
|
|
window.addEventListener('storage', function (e) {
|
|
|
|
window.addEventListener('storage', function (e) {
|
|
|
|
if (e.key !== common.userHashKey) { return; }
|
|
|
|
if (e.key !== Constants.userHashKey) { return; }
|
|
|
|
var o = e.oldValue;
|
|
|
|
var o = e.oldValue;
|
|
|
|
var n = e.newValue;
|
|
|
|
var n = e.newValue;
|
|
|
|
if (!o && n) {
|
|
|
|
if (!o && n) {
|
|
|
|