diff --git a/customize.dist/translations/messages.de.js b/customize.dist/translations/messages.de.js
index 8b1139836..5915b4684 100644
--- a/customize.dist/translations/messages.de.js
+++ b/customize.dist/translations/messages.de.js
@@ -103,8 +103,6 @@
out.notifyRenamed = "{0} heißt nun {1}";
out.notifyLeft = "{0} hat die gemeinsame Sitzung verlassen";
- out.disconnectAlert = 'Netzwerkverbindung verloren!';
-
out.tryIt = 'Probier\'s aus!';
out.recentPads = 'Deine letzten Pads (diese Liste ist nur in deinem Browser gespeichert))';
diff --git a/customize.dist/translations/messages.es.js b/customize.dist/translations/messages.es.js
index e6f8460bb..be6f87b29 100644
--- a/customize.dist/translations/messages.es.js
+++ b/customize.dist/translations/messages.es.js
@@ -100,8 +100,6 @@ define(function () {
out.notifyRenamed = "{0} ahora se conoce como {1}";
out.notifyLeft = "{0} ha dejado la sesión de colaboración";
- out.disconnectAlert = '¡Conexión a la red perdida!';
-
out.tryIt = '¡PROBARLO!';
out.recentPads = 'Tus documentos recientes (almacenadas solo en el navegador)';
diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js
index 1bc60132e..89237f351 100644
--- a/customize.dist/translations/messages.fr.js
+++ b/customize.dist/translations/messages.fr.js
@@ -118,8 +118,6 @@ define(function () {
out.notifyRenamed = "{0} a changé son nom en {1}";
out.notifyLeft = "{0} a quitté la session collaborative";
- out.disconnectAlert = 'Perte de la connexion au réseau !';
-
out.okButton = 'OK (Entrée)';
out.cancel = "Annuler";
@@ -244,7 +242,8 @@ define(function () {
// login
out.login_login = "Connexion";
- out.login_nologin = "Documents récents de ce navigateur";
+ out.login_makeAPad = 'Créer un document anonymement';
+ out.login_nologin = "Voir les documents récents";
out.login_register = "Inscription";
out.logoutButton = "Déconnexion";
@@ -253,9 +252,9 @@ define(function () {
out.username_label = "Nom d'utilisateur : ";
out.displayname_label = "Nom affiché : ";
- out.login_username = "votre nom d'utilisateur";
- out.login_password = "votre mot de passe";
- out.login_confirm = "confirmer votre mot de passe";
+ out.login_username = "Nom d'utilisateur";
+ out.login_password = "Mot de passe";
+ out.login_confirm = "Confirmer votre mot de passe";
out.login_remember = "Se souvenir de moi";
out.login_cancel_prompt = "...ou si vous avez entré le mauvais nom d'utilisateur ou mot de passe, annulez pour essayer à nouveau.";
@@ -281,11 +280,12 @@ define(function () {
out.login_hello = 'Bonjour {0},'; // {0} is the username
out.login_helloNoName = 'Bonjour,';
out.login_accessDrive = 'Accédez à votre drive';
+ out.login_orNoLogin = 'ou';
// index.html
//out.main_p1 = 'CryptPad est l\'éditeur collaboratif en temps réel zero knowledge. Le chiffrement est effectué depuis votre navigateur, ce qui protège les données contre le serveur, le cloud, et la NSA. La clé de chiffrement est stockée dans l\'identifieur de fragment de l\'URL qui n\'est jamais envoyée au serveur mais est accessible depuis javascript, de sorte qu\'en partageant l\'URL, vous donnez l\'accès au pad à ceux qui souhaitent participer.';
- out.main_p1 = "
Collaborez en tout confiance
Développez vos idées collaborativement grâce à des documents partagés en temps-réel, tout en gardant vos données personnelles invisibles, même pour nous, avec la technologie Zero Knowledge.";
+ out.main_p1 = "
Collaborez avec confiance
Développez vos idées en groupe avec des documents partagés; la technologie Zero Knowledge sécurise vos données.";
out.main_p2 = 'Ce projet utilise l\'éditeur visuel (WYSIWYG) CKEditor, l\'éditeur de code source CodeMirror, et le moteur temps-réel ChainPad.';
out.main_howitworks_p1 = 'CryptPad utilise une variante de l\'algorithme d\'Operational transformation qui est capable de trouver un consensus distribué en utilisant une chaîne de bloc Nakamoto, un outil popularisé par le Bitcoin. De cette manière, l\'algorithme évite la nécessité d\'utiliser un serveur central pour résoudre les conflits d\'édition de l\'Operational Transformation, et sans ce besoin de résolution des conflits le serveur peut rester ignorant du contenu qui est édité dans le pad.';
out.main_about = 'À propos';
@@ -295,9 +295,9 @@ define(function () {
out.main_howitworks = 'Comment ça fonctionne';
out.main_zeroKnowledge = 'Zero Knowledge';
- out.main_zeroKnowledge_p = "Vous n'avez pas besoin de croire que nous n'allons pas regarder vos documents. Avec la technologie Zero Knowledge de Cryptpad, nous ne pouvons pas le faire. Apprenez-en plus sur notre manière de protéger vos données.";
- out.main_jotItDown = 'Prenez-en note';
- out.main_jotItDown_p = "Les plus grands projets naissent des plus petites idées. Prenez note de vos moments d'inspiration et de vos idées inattendues car vous ne savez pas lesquels seront des découvertes capitales.";
+ out.main_zeroKnowledge_p = "Vous n'avez pas besoin de croire que nous n'allons pas regarder vos documents. Avec la technologie Zero Knowledge de Cryptpad, nous ne pouvons pas le faire. Apprenez-en plus sur notre manière de protéger vos données.";
+ out.main_writeItDown = 'Prenez-en note';
+ out.main_writeItDown_p = "Les plus grands projets naissent des plus petites idées. Prenez note de vos moments d'inspiration et de vos idées inattendues car vous ne savez pas lesquels seront des découvertes capitales.";
out.main_share = 'Partager le lien, partager le document';
out.main_share_p = "Faites croître vos idées à plusieurs : réalisez des réunions efficaes, collaborez sur vos listes de tâches et réalisez des présentations rapide avec tous vos amis sur tous vos appareils.";
out.main_organize = 'Soyez organisés';
@@ -322,7 +322,6 @@ define(function () {
out.table_created = 'Créé le';
out.table_last = 'Dernier accès';
- out.makeAPad = 'Créer un document';
out.button_newpad = 'Nouveau document texte';
out.button_newcode = 'Nouvelle page de code';
out.button_newpoll = 'Nouveau sondage';
diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js
index ee09575e7..a93110b84 100644
--- a/customize.dist/translations/messages.js
+++ b/customize.dist/translations/messages.js
@@ -122,8 +122,6 @@ define(function () {
out.notifyRenamed = "{0} is now known as {1}";
out.notifyLeft = "{0} has left the collaborative session";
- out.disconnectAlert = 'Network connection lost!';
-
out.okButton = 'OK (enter)';
out.cancel = "Cancel";
@@ -245,7 +243,8 @@ define(function () {
// login
out.login_login = "Log in";
- out.login_nologin = "Your browser's recent pads";
+ out.login_makeAPad = 'Create a pad anonymously';
+ out.login_nologin = "Browse local pads";
out.login_register = "Sign up";
out.logoutButton = "Log out";
@@ -254,9 +253,9 @@ define(function () {
out.username_label = "Username: ";
out.displayname_label = "Display name: ";
- out.login_username = "your username";
- out.login_password = "your password";
- out.login_confirm = "confirm your password";
+ out.login_username = "Username";
+ out.login_password = "Password";
+ out.login_confirm = "Confirm your password";
out.login_remember = "Remember me";
out.login_cancel_prompt = "...or if you may have entered the wrong username or password, cancel to try again.";
@@ -282,6 +281,7 @@ define(function () {
out.login_hello = 'Hello {0},'; // {0} is the username
out.login_helloNoName = 'Hello,';
out.login_accessDrive = 'Access your drive';
+ out.login_orNoLogin = 'or';
// index.html
@@ -298,7 +298,7 @@ define(function () {
out.main_howitworks = 'How It Works';
out.main_zeroKnowledge = 'Zero Knowledge';
- out.main_zeroKnowledge_p = "You don't have to trust that we won't look at your pads, with CryptPad's revolutionary Zero Knowledge Technology we can't. Learn more about how we protect your Privacy and Security.";
+ out.main_zeroKnowledge_p = "You don't have to trust that we won't look at your pads, with CryptPad's revolutionary Zero Knowledge Technology we can't. Learn more about how we protect your Privacy and Security.";
out.main_writeItDown = 'Write it down';
out.main_writeItDown_p = "The greatest projects come from the smallest ideas. Take down the moments of inspiration and unexpected ideas because you never know which one might be a breakthrough.";
out.main_share = 'Share the link, share the pad';
@@ -325,7 +325,6 @@ define(function () {
out.table_created = 'Created';
out.table_last = 'Last Accessed';
- out.makeAPad = 'Make a pad right now';
out.button_newpad = 'New Rich Text pad';
out.button_newcode = 'New Code pad';
out.button_newpoll = 'New Poll';
diff --git a/customize.dist/translations/messages.pl.js b/customize.dist/translations/messages.pl.js
index 65e0c2abf..de4a20a38 100644
--- a/customize.dist/translations/messages.pl.js
+++ b/customize.dist/translations/messages.pl.js
@@ -102,8 +102,6 @@ define(function () {
out.notifyRenamed = "{0} jest teraz znany jako {1}";
out.notifyLeft = "{0} opuścił sesję współpracy";
- out.disconnectAlert = 'Utracono połączenie sieciowe!';
-
out.tryIt = 'Wypróbuj!';
out.recentPads = 'Ostatnio otwarte dokumenty (przechowywane jedynie w twojej przeglądarce)';
diff --git a/customize.dist/translations/messages.pt-br.js b/customize.dist/translations/messages.pt-br.js
index a2aaec567..ba737b62f 100644
--- a/customize.dist/translations/messages.pt-br.js
+++ b/customize.dist/translations/messages.pt-br.js
@@ -110,8 +110,6 @@ define(function () {
out.notifyRenamed = "{0} agora é conhecido como {1}";
out.notifyLeft = "{0} deixou essa sessão colaborativa";
- out.disconnectAlert = 'Conexão de rede perdida!';
-
out.tryIt = 'Experimente!';
out.recentPads = 'Seu bloco de nota recente (armazenado em seu navegador)';
diff --git a/www/code/main.js b/www/code/main.js
index ba1208a2d..92c63560c 100644
--- a/www/code/main.js
+++ b/www/code/main.js
@@ -699,7 +699,7 @@ define([
// inform of network disconnect
setEditable(false);
toolbar.failed();
- Cryptpad.alert(Messages.disconnectAlert);
+ Cryptpad.alert(Messages.common_connectionLost);
};
var onConnectionChange = config.onConnectionChange = function (info) {
@@ -710,7 +710,7 @@ define([
toolbar.reconnecting(info.myId);
Cryptpad.findOKButton().click();
} else {
- Cryptpad.alert(Messages.disconnectAlert);
+ Cryptpad.alert(Messages.common_connectionLost);
}
};
diff --git a/www/user/credential.js b/www/common/credential.js
similarity index 100%
rename from www/user/credential.js
rename to www/common/credential.js
diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js
index ff2943c16..bc41fc4e5 100644
--- a/www/common/cryptpad-common.js
+++ b/www/common/cryptpad-common.js
@@ -1,7 +1,7 @@
define([
'/api/config?cb=' + Math.random().toString(16).slice(2),
'/customize/messages.js',
- '/customize/store.js',
+ '/customize/fsStore.js',
'/bower_components/chainpad-crypto/crypto.js',
'/bower_components/alertifyjs/dist/js/alertify.js',
'/bower_components/spin.js/spin.min.js',
@@ -10,7 +10,7 @@ define([
'/customize/application_config.js',
'/bower_components/jquery/dist/jquery.min.js',
-], function (Config, Messages, Store, Crypto, Alertify, Spinner, Clipboard, FS, AppConfig) {
+], function (Config, Messages, Store, Crypto, Alertify, Spinner, Clipboard, AppConfig) {
/* This file exposes functionality which is specific to Cryptpad, but not to
any particular pad type. This includes functions for committing metadata
about pads to your local storage for future use and improved usability.
@@ -19,18 +19,11 @@ define([
*/
var $ = window.jQuery;
- // When set to true, USE_FS_STORE becomes the default store, but the localStorage store is
- // still loaded for migration purpose. When false, the localStorage is used.
- var USE_FS_STORE = AppConfig.USE_FS_STORE;
-
- var storeToUse = USE_FS_STORE ? FS : Store;
-
var common = window.Cryptpad = {
Messages: Messages,
Alertify: Alertify,
};
var store;
- var fsStore;
var find = common.find = function (map, path) {
return (map && path.reduce(function (p, n) {
@@ -38,15 +31,14 @@ define([
}, map));
};
- var getStore = common.getStore = function (legacy) {
- if ((!USE_FS_STORE || legacy) && store) { return store; }
- if (USE_FS_STORE && !legacy && fsStore) { return fsStore; }
+ var getStore = common.getStore = function () {
+ if (store) { return store; }
throw new Error("Store is not ready!");
};
var getNetwork = common.getNetwork = function () {
- if (USE_FS_STORE && fsStore) {
- if (fsStore.getProxy() && fsStore.getProxy().info) {
- return fsStore.getProxy().info.network;
+ if (store) {
+ if (store.getProxy() && store.getProxy().info) {
+ return store.getProxy().info.network;
}
}
return;
@@ -131,7 +123,6 @@ define([
};
var isLoggedIn = common.isLoggedIn = function () {
- //return typeof getStore().getLoginName() === "string";
return typeof getUserHash() === "string";
};
@@ -373,6 +364,23 @@ define([
});
};
+ // Get the pads from localStorage to migrate them to the object store
+ var getLegacyPads = common.getLegacyPads = function (cb) {
+ require(['/customize/store.js'], function(Legacy) {
+ Legacy.ready(function (err, legacy) {
+ if (err) { cb(err, null); return; }
+ Legacy.get(storageKey, function (err2, recentPads) {
+ if (err2) { cb(err2, null); return; }
+ if (isArray(recentPads)) {
+ cb(void 0, migrateRecentPads(recentPads));
+ return;
+ }
+ cb(void 0, []);
+ });
+ });
+ });
+ };
+
var getHash = common.getHash = function () {
return window.location.hash.slice(1);
};
@@ -446,13 +454,13 @@ define([
};
// STORAGE
- var setPadAttribute = common.setPadAttribute = function (attr, value, cb, legacy) {
- getStore(legacy).setDrive([getHash(), attr].join('.'), value, function (err, data) {
+ var setPadAttribute = common.setPadAttribute = function (attr, value, cb) {
+ getStore().setDrive([getHash(), attr].join('.'), value, function (err, data) {
cb(err, data);
});
};
- var setAttribute = common.setAttribute = function (attr, value, cb, legacy) {
- getStore(legacy).set(["cryptpad", attr].join('.'), value, function (err, data) {
+ var setAttribute = common.setAttribute = function (attr, value, cb) {
+ getStore().set(["cryptpad", attr].join('.'), value, function (err, data) {
cb(err, data);
});
};
@@ -461,13 +469,13 @@ define([
};
// STORAGE
- var getPadAttribute = common.getPadAttribute = function (attr, cb, legacy) {
- getStore(legacy).getDrive([getHash(), attr].join('.'), function (err, data) {
+ var getPadAttribute = common.getPadAttribute = function (attr, cb) {
+ getStore().getDrive([getHash(), attr].join('.'), function (err, data) {
cb(err, data);
});
};
- var getAttribute = common.getAttribute = function (attr, cb, legacy) {
- getStore(legacy).get(["cryptpad", attr].join('.'), function (err, data) {
+ var getAttribute = common.getAttribute = function (attr, cb) {
+ getStore().get(["cryptpad", attr].join('.'), function (err, data) {
cb(err, data);
});
};
@@ -493,12 +501,8 @@ define([
// STORAGE
/* fetch and migrate your pad history from localStorage */
- var getRecentPads = common.getRecentPads = function (cb, legacy) {
- var sstore = getStore(legacy);
- if (legacy) {
- sstore.getDrive = sstore.get;
- }
- sstore.getDrive(storageKey, function (err, recentPads) {
+ var getRecentPads = common.getRecentPads = function (cb) {
+ getStore().getDrive(storageKey, function (err, recentPads) {
if (isArray(recentPads)) {
cb(void 0, migrateRecentPads(recentPads));
return;
@@ -509,21 +513,14 @@ define([
// STORAGE
/* commit a list of pads to localStorage */
- var setRecentPads = common.setRecentPads = function (pads, cb, legacy) {
- var sstore = getStore(legacy);
- if (legacy) {
- sstore.setDrive = sstore.set;
- }
- sstore.setDrive(storageKey, pads, function (err, data) {
+ var setRecentPads = common.setRecentPads = function (pads, cb) {
+ getStore().setDrive(storageKey, pads, function (err, data) {
cb(err, data);
});
};
// STORAGE
- var forgetFSPad = function (href, cb) {
- getStore().forgetPad(href, cb);
- };
- var forgetPad = common.forgetPad = function (href, cb, legacy) {
+ var forgetPad = common.forgetPad = function (href, cb) {
var parsed = parsePadUrl(href);
var callback = function (err, data) {
@@ -532,7 +529,7 @@ define([
return;
}
- getStore(legacy).keys(function (err, keys) {
+ getStore().keys(function (err, keys) {
if (err) {
cb(err);
return;
@@ -545,35 +542,14 @@ define([
cb();
return;
}
- getStore(legacy).removeBatch(toRemove, function (err, data) {
+ getStore().removeBatch(toRemove, function (err, data) {
cb(err, data);
});
});
};
- if (USE_FS_STORE && !legacy) {
- // TODO implement forgetPad in store.js
- forgetFSPad(href, callback);
- return;
- }
-
- getRecentPads(function (err, recentPads) {
- setRecentPads(recentPads.filter(function (pad) {
- var p = parsePadUrl(pad.href);
- // find duplicates
- if (parsed.hash === p.hash && parsed.type === p.type) {
- console.log("Found a duplicate");
- return;
- }
- return true;
- }), callback, legacy);
- }, legacy);
-
-
-
- if (typeof(getStore(legacy).forgetPad) === "function") {
- // TODO implement forgetPad in store.js
- getStore(legacy).forgetPad(href, callback);
+ if (typeof(getStore().forgetPad) === "function") {
+ getStore().forgetPad(href, callback);
}
};
@@ -626,7 +602,7 @@ define([
if (!contains) {
var data = makePad(href, name);
renamed.push(data);
- if (USE_FS_STORE && typeof(getStore().addPad) === "function") {
+ if (typeof(getStore().addPad) === "function") {
getStore().addPad(href, common.initialPath, common.initialName || name);
}
}
@@ -701,58 +677,47 @@ define([
f(void 0, env);
};
- var todo = function () {
- storeToUse.ready(function (err, store) {
- common.store = env.store = store;
- if (USE_FS_STORE) {
- fsStore = store;
- }
+ Store.ready(function (err, storeObj) {
+ store = common.store = env.store = storeObj;
- $(function() {
- // Race condition : if document.body is undefined when alertify.js is loaded, Alertify
- // won't work. We have to reset it now to make sure it uses a correct "body"
- Alertify.reset();
+ $(function() {
+ // Race condition : if document.body is undefined when alertify.js is loaded, Alertify
+ // won't work. We have to reset it now to make sure it uses a correct "body"
+ Alertify.reset();
- // Load the new pad when the hash has changed
- var oldHash = document.location.hash.slice(1);
- window.onhashchange = function () {
- var newHash = document.location.hash.slice(1);
- var parsedOld = parseHash(oldHash);
- var parsedNew = parseHash(newHash);
- if (parsedOld && parsedNew && (
- parsedOld.channel !== parsedNew.channel
- || parsedOld.mode !== parsedNew.mode
- || parsedOld.key !== parsedNew.key)) {
- document.location.reload();
- return;
- }
- if (parsedNew) {
- oldHash = newHash;
- }
- };
-
- // Everything's ready, continue...
- if($('#pad-iframe').length) {
- var $iframe = $('#pad-iframe');
- var iframe = $iframe[0];
- var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
- if (iframeDoc.readyState === 'complete') {
- cb();
- return;
- }
- $iframe.load(cb);
+ // Load the new pad when the hash has changed
+ var oldHash = document.location.hash.slice(1);
+ window.onhashchange = function () {
+ var newHash = document.location.hash.slice(1);
+ var parsedOld = parseHash(oldHash);
+ var parsedNew = parseHash(newHash);
+ if (parsedOld && parsedNew && (
+ parsedOld.channel !== parsedNew.channel
+ || parsedOld.mode !== parsedNew.mode
+ || parsedOld.key !== parsedNew.key)) {
+ document.location.reload();
return;
}
- cb();
- });
- }, common);
- };
- // If we use the fs store, make sure the localStorage or iframe store is ready
- if (USE_FS_STORE) {
- Store.ready(todo);
- return;
- }
- todo();
+ if (parsedNew) {
+ oldHash = newHash;
+ }
+ };
+
+ // Everything's ready, continue...
+ if($('#pad-iframe').length) {
+ var $iframe = $('#pad-iframe');
+ var iframe = $iframe[0];
+ var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
+ if (iframeDoc.readyState === 'complete') {
+ cb();
+ return;
+ }
+ $iframe.load(cb);
+ return;
+ }
+ cb();
+ });
+ }, common);
};
var errorHandlers = [];
@@ -1263,15 +1228,6 @@ define([
};
};
- // All code which is called implicitly is found below
- Store.ready(function (err, Store) {
- if (err) {
- console.error(err);
- return;
- }
- store = Store;
- });
-
$(function () {
Messages._applyTranslation();
});
diff --git a/www/common/login.js b/www/common/login.js
new file mode 100644
index 000000000..bf3848c70
--- /dev/null
+++ b/www/common/login.js
@@ -0,0 +1,112 @@
+define([
+ '/bower_components/chainpad-listmap/chainpad-listmap.js',
+ '/bower_components/chainpad-crypto/crypto.js',
+ '/common/cryptpad-common.js',
+ '/common/credential.js',
+ '/bower_components/tweetnacl/nacl-fast.min.js',
+ '/bower_components/scrypt-async/scrypt-async.min.js', // better load speed
+ '/bower_components/jquery/dist/jquery.min.js',
+], function (Listmap, Crypto, Cryptpad, Cred) {
+ var Exports = {
+ Cred: Cred,
+ };
+
+ var allocateBytes = function (bytes) {
+ var dispense = Cred.dispenser(bytes);
+
+ var opt = {};
+
+ // dispense 18 bytes of entropy for your encryption key
+ var encryptionSeed = dispense(18);
+ // 16 bytes for a deterministic channel key
+ var channelSeed = dispense(16);
+ // 32 bytes for a curve key
+ var curveSeed = opt.curveSeed = dispense(32);
+ // 32 more for a signing key
+ var edSeed = opt.edSeed = dispense(32);
+
+ var keys = opt.keys = Crypto.createEditCryptor(null, encryptionSeed);
+
+ // 24 bytes of base64
+ keys.editKeyStr = keys.editKeyStr.replace(/\//g, '-');
+
+ // 32 bytes of hex
+ var channelHex = opt.channelHex = Cryptpad.uint8ArrayToHex(channelSeed);
+
+ // should never happen
+ if (channelHex.length !== 32) { throw new Error('invalid channel id'); }
+
+ var channel64 = opt.channel64 = Cryptpad.hexToBase64(channelHex);
+
+ var userHash = opt.userHash = '/1/edit/' + [opt.channel64, opt.keys.editKeyStr].join('/');
+
+ return opt;
+ };
+
+ var loadUserObject = function (opt, cb) {
+ var config = {
+ websocketURL: Cryptpad.getWebsocketURL(),
+ channel: opt.channelHex,
+ data: {},
+ validateKey: opt.keys.validateKey, // derived validation key
+ crypto: Crypto.createEncryptor(opt.keys),
+ logLevel: 1,
+ };
+
+ var rt = opt.rt = Listmap.create(config);
+ rt.proxy
+ .on('ready', function (info) {
+ cb(void 0, rt);
+ })
+ .on('disconnect', function (info) {
+ cb('E_DISCONNECT', info);
+ });
+ };
+
+ var isProxyEmpty = function (proxy) {
+ return Object.keys(proxy).length === 0;
+ };
+
+ Exports.loginOrRegister = function (uname, passwd, isRegister, cb) {
+ if (typeof(cb) !== 'function') { return; }
+
+ // validate inputs
+ if (!Cred.isValidUsername(uname)) { return void cb('INVAL_USER'); }
+ if (!Cred.isValidPassword(passwd)) { return void cb('INVAL_PASS'); }
+
+ Cred.deriveFromPassphrase(uname, passwd, 128, function (bytes) {
+ // results...
+ var res = {
+ register: isRegister,
+ };
+
+ // run scrypt to derive the user's keys
+ var opt = res.opt = allocateBytes(bytes);
+
+ // use the derived key to generate an object
+ loadUserObject(opt, function (err, rt) {
+ if (err) { return void cb(err); }
+
+ res.proxy = rt.proxy;
+ res.realtime = rt.realtime;
+ res.network = rt.network;
+
+ // they tried to just log in but there's no such user
+ if (!isRegister && isProxyEmpty(rt.proxy)) {
+ rt.network.disconnect(); // clean up after yourself
+ return void cb('NO_SUCH_USER', res);
+ }
+
+ // they're registering...
+
+ res.userHash = opt.userHash;
+ res.userName = uname;
+ //res.displayName // TODO
+
+ cb(void 0, res);
+ });
+ });
+ };
+
+ return Exports;
+});
diff --git a/www/drive/main.js b/www/drive/main.js
index 6cbad00ec..83fc6eb26 100644
--- a/www/drive/main.js
+++ b/www/drive/main.js
@@ -9,8 +9,9 @@ define([
'/common/cryptpad-common.js',
'/common/fileObject.js',
'/common/toolbar.js',
- '/customize/application_config.js'
-], function (Config, Listmap, Crypto, TextPatcher, Messages, JSONSortify, Cryptpad, FO, Toolbar, AppConfig) {
+ '/customize/application_config.js',
+ '/common/cryptget.js'
+], function (Config, Listmap, Crypto, TextPatcher, Messages, JSONSortify, Cryptpad, FO, Toolbar, AppConfig, Get) {
var module = window.MODULE = {};
var $ = window.jQuery;
@@ -1854,6 +1855,31 @@ define([
});
};
+ // TODO: move that function and use a more generic API
+ var migrateAnonDrive = function (proxy, cb) {
+ if (sessionStorage.migrateAnonDrive) {
+ // Make sure we have an FS_hash and we don't use it, otherwise just stop the migration and cb
+ if (!localStorage.FS_hash || !APP.loggedIn) {
+ delete sessionStorage.migrateAnonDrive;
+ if (typeof(cb) === "function") { cb(); }
+ }
+ // Get the content of FS_hash and then merge the objects, remove the migration key and cb
+ var todo = function (err, doc) {
+ if (err) { logError("Cannot migrate recent pads", err); return; }
+ var parsed;
+ try { parsed = JSON.parse(doc); } catch (e) { logError("Cannot parsed recent pads", e); }
+ if (parsed) {
+ $.extend(true, proxy, parsed);
+ }
+ delete sessionStorage.migrateAnonDrive;
+ if (typeof(cb) === "function") { cb(); }
+ };
+ Get.get(localStorage.FS_hash, todo);
+ } else {
+ if (typeof(cb) === "function") { cb(); }
+ }
+ };
+
// don't initialize until the store is ready.
Cryptpad.ready(function () {
APP.$bar = $iframe.find('#toolbar');
@@ -1950,23 +1976,13 @@ define([
};
var onReady = function () {
module.files = proxy;
- if (JSON.stringify(proxy) === '{}') {
- var store = Cryptpad.getStore(true);
- var drive = proxy.drive = {};
- store.get(Cryptpad.storageKey, function (err, s) {
- drive[FILES_DATA] = s;
- initLocalStorage();
- init(proxy);
- APP.userList.onChange();
- Cryptpad.removeLoadingScreen();
- });
- return;
- }
if (!proxy.drive || typeof(proxy.drive) !== 'object') { proxy.drive = {}; }
- initLocalStorage();
- init(proxy);
- APP.userList.onChange();
- Cryptpad.removeLoadingScreen();
+ migrateAnonDrive(proxy, function () {
+ initLocalStorage();
+ init(proxy);
+ APP.userList.onChange();
+ Cryptpad.removeLoadingScreen();
+ });
};
var onDisconnect = function (info) {
setEditable(false);
diff --git a/www/pad/main.js b/www/pad/main.js
index 34a587afa..4ad0c207e 100644
--- a/www/pad/main.js
+++ b/www/pad/main.js
@@ -739,7 +739,7 @@ define([
setEditable(false);
// TODO inform them that the session was torn down
toolbar.failed();
- Cryptpad.alert(Messages.disconnectAlert);
+ Cryptpad.alert(Messages.common_connectionLost);
};
var onConnectionChange = realtimeOptions.onConnectionChange = function (info) {
@@ -750,7 +750,7 @@ define([
toolbar.reconnecting(info.myId);
Cryptpad.findOKButton().click();
} else {
- Cryptpad.alert(Messages.disconnectAlert);
+ Cryptpad.alert(Messages.common_connectionLost);
}
};
diff --git a/www/register/index.html b/www/register/index.html
new file mode 100644
index 000000000..0976f9360
--- /dev/null
+++ b/www/register/index.html
@@ -0,0 +1,67 @@
+
+
+
+
+
+ Cryptpad: login
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/www/register/main.js b/www/register/main.js
new file mode 100644
index 000000000..5c42872bf
--- /dev/null
+++ b/www/register/main.js
@@ -0,0 +1,43 @@
+define([
+ '/common/login.js',
+ '/common/credential.js',
+ '/bower_components/jquery/dist/jquery.min.js',
+], function (Login) {
+ var $ = window.jQuery;
+
+ // text and password input fields
+ var $uname = $('#username');
+ var $passwd = $('#password');
+ var $confirm = $('#password-confirm');
+
+ // checkboxes
+ var $checkImport = $('#import-recent');
+ var $checkAcceptTerms = $('#accept-terms');
+ var $checkPromise = $('#promise');
+
+ var $register = $('button#register');
+
+ $register.click(function () {
+ var uname = $uname.val();
+ var passwd = $passwd.val();
+ var confirmPassword = $confirm.val();
+
+ var shouldImport = $checkImport[0].checked;
+ var doesAccept = $checkAcceptTerms[0].checked;
+ var doesPromise = $checkPromise[0].checked;
+
+ /* basic validation */
+
+ // do their passwords match?
+
+ if (passwd !== confirmPassword) {
+ alert('invalid password');
+ return;
+ }
+
+ Login.loginOrRegister(uname, passwd, true, function (err, out) {
+ if (err) { alert(err); }
+ console.log(out);
+ })
+ });
+});
diff --git a/www/slide/main.js b/www/slide/main.js
index 226e0249e..7c75a42ce 100644
--- a/www/slide/main.js
+++ b/www/slide/main.js
@@ -782,7 +782,7 @@ define([
// inform of network disconnect
setEditable(false);
toolbar.failed();
- Cryptpad.alert(Messages.disconnectAlert);
+ Cryptpad.alert(Messages.common_connectionLost);
};
var onConnectionChange = config.onConnectionChange = function (info) {
@@ -793,7 +793,7 @@ define([
toolbar.reconnecting(info.myId);
Cryptpad.findOKButton().click();
} else {
- Cryptpad.alert(Messages.disconnectAlert);
+ Cryptpad.alert(Messages.common_connectionLost);
}
};
diff --git a/www/user/main.js b/www/user/main.js
index 039316ef5..8d86d6b9c 100644
--- a/www/user/main.js
+++ b/www/user/main.js
@@ -1,13 +1,13 @@
define([
- '/api/config?cb=' + Math.random().toString(16).substring(2),
'/bower_components/chainpad-listmap/chainpad-listmap.js',
'/bower_components/chainpad-crypto/crypto.js',
'/common/cryptpad-common.js',
- 'credential.js',
+ '/common/credential.js',
+ '/common/login.js',
'/bower_components/tweetnacl/nacl-fast.min.js',
'/bower_components/scrypt-async/scrypt-async.min.js', // better load speed
'/bower_components/jquery/dist/jquery.min.js',
-], function (Config, Listmap, Crypto, Cryptpad, Cred) {
+], function (Listmap, Crypto, Cryptpad, Cred, Login) {
var $ = window.jQuery;
var Nacl = window.nacl;
@@ -16,6 +16,7 @@ define([
var APP = window.APP = {
Cryptpad: Cryptpad,
Crypto: Crypto,
+ Login: Login,
};
// login elements
@@ -161,6 +162,9 @@ define([
});
};
+ addEnterListener($confirm, function () {
+ $register.click();
+ });
addEnterListener($password_register, function () {
$login.click();
});
@@ -354,7 +358,9 @@ define([
APP.setNotice(Cryptpad.Messages.login_hashing);
+ // inform the user that we're hashing their password
revealNotice(true);
+
revealLogin(false, function () {
window.setTimeout(function () {
resetUI();