From dd014f6ef2b59b6c68a8e95b5a3ba7b1c4c41979 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 17 Feb 2017 15:16:03 +0100 Subject: [PATCH 01/11] Fix race conditon --- www/drive/main.js | 9 +-- www/register/main.js | 158 +++++++++++++++++++++---------------------- 2 files changed, 84 insertions(+), 83 deletions(-) diff --git a/www/drive/main.js b/www/drive/main.js index 9bdf42e4a..3f7335c95 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -16,11 +16,12 @@ define([ var $ = window.jQuery; var saveAs = window.saveAs; - var $iframe = $('#pad-iframe').contents(); - var ifrw = $('#pad-iframe')[0].contentWindow; - + // Use `$(function () {});` to make sure the html is loaded before doing anything else + $(function () { + var $iframe = $('#pad-iframe').contents(); + var ifrw = $('#pad-iframe')[0].contentWindow; Cryptpad.addLoadingScreen(); var onConnectError = function (info) { @@ -2032,5 +2033,5 @@ define([ } }); - + }); }); diff --git a/www/register/main.js b/www/register/main.js index d5e17c228..c41825595 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -39,101 +39,101 @@ define([ } else { $main.find('#userForm').removeClass('hidden'); } - }); - // text and password input fields - var $uname = $('#username'); - var $passwd = $('#password'); - var $confirm = $('#password-confirm'); + // text and password input fields + var $uname = $('#username'); + var $passwd = $('#password'); + var $confirm = $('#password-confirm'); - if (sessionStorage.login_user) { - $uname.val(sessionStorage.login_user); - } - if (sessionStorage.login_pass) { - $passwd.val(sessionStorage.login_pass); - } + if (sessionStorage.login_user) { + $uname.val(sessionStorage.login_user); + } + if (sessionStorage.login_pass) { + $passwd.val(sessionStorage.login_pass); + } - [ $uname, $passwd, $confirm] - .some(function ($el) { if (!$el.val()) { $el.focus(); return true; } }); + [ $uname, $passwd, $confirm] + .some(function ($el) { if (!$el.val()) { $el.focus(); return true; } }); - // checkboxes - var $checkImport = $('#import-recent'); - var $checkAcceptTerms = $('#accept-terms'); - var $checkPromise = $('#promise'); + // checkboxes + var $checkImport = $('#import-recent'); + var $checkAcceptTerms = $('#accept-terms'); + var $checkPromise = $('#promise'); - var $register = $('button#register'); + var $register = $('button#register'); - $register.click(function () { - var uname = $uname.val(); - var passwd = $passwd.val(); - var confirmPassword = $confirm.val(); + $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; + var shouldImport = $checkImport[0].checked; + var doesAccept = $checkAcceptTerms[0].checked; + var doesPromise = $checkPromise[0].checked; - /* basic validation */ - if (passwd !== confirmPassword) { // do their passwords match? - return void Cryptpad.alert(Messages.register_passwordsDontMatch); - } + /* basic validation */ + if (passwd !== confirmPassword) { // do their passwords match? + return void Cryptpad.alert(Messages.register_passwordsDontMatch); + } - if (!doesAccept) { // do they accept the terms of service? - return void Cryptpad.alert(Messages.register_mustAcceptTerms); - } + if (!doesAccept) { // do they accept the terms of service? + return void Cryptpad.alert(Messages.register_mustAcceptTerms); + } - if (!doesPromise) { // do they promise to remember their password? - return void Cryptpad.alert(Messages.register_mustRememberPass); - } + if (!doesPromise) { // do they promise to remember their password? + return void Cryptpad.alert(Messages.register_mustRememberPass); + } - Cryptpad.addLoadingScreen(Messages.login_hashing); - Login.loginOrRegister(uname, passwd, true, function (err, result) { - if (err) { - switch (err) { - case 'NO_SUCH_USER': - Cryptpad.removeLoadingScreen(function () { - Cryptpad.alert(Messages.login_noSuchUser); - }); - break; - case 'INVAL_USER': - Cryptpad.removeLoadingScreen(function () { - Cryptpad.alert(Messages.login_invalUser); - }); - break; - case 'INVAL_PASS': - Cryptpad.removeLoadingScreen(function () { - Cryptpad.alert(Messages.login_invalPass); - }); - break; - default: // UNHANDLED ERROR - Cryptpad.errorLoadingScreen(Messages.login_unhandledError); + Cryptpad.addLoadingScreen(Messages.login_hashing); + Login.loginOrRegister(uname, passwd, true, function (err, result) { + if (err) { + switch (err) { + case 'NO_SUCH_USER': + Cryptpad.removeLoadingScreen(function () { + Cryptpad.alert(Messages.login_noSuchUser); + }); + break; + case 'INVAL_USER': + Cryptpad.removeLoadingScreen(function () { + Cryptpad.alert(Messages.login_invalUser); + }); + break; + case 'INVAL_PASS': + Cryptpad.removeLoadingScreen(function () { + Cryptpad.alert(Messages.login_invalPass); + }); + break; + default: // UNHANDLED ERROR + Cryptpad.errorLoadingScreen(Messages.login_unhandledError); + } } - } - var proxy = result.proxy; + var proxy = result.proxy; - localStorage.User_hash = result.userHash; + localStorage.User_hash = result.userHash; - Cryptpad.eraseTempSessionValues(); - if (shouldImport) { - sessionStorage.migrateAnonDrive = 1; - } + Cryptpad.eraseTempSessionValues(); + if (shouldImport) { + sessionStorage.migrateAnonDrive = 1; + } - proxy.login_name = uname; - proxy[Cryptpad.displayNameKey] = uname; - proxy.initializing = true; - - Cryptpad.whenRealtimeSyncs(result.realtime, function () { - Cryptpad.login(result.userHash, result.userName, function () { - if (sessionStorage.redirectTo) { - var h = sessionStorage.redirectTo; - var parser = document.createElement('a'); - parser.href = h; - if (parser.origin === window.location.origin) { - delete sessionStorage.redirectTo; - window.location.href = h; - return; + proxy.login_name = uname; + proxy[Cryptpad.displayNameKey] = uname; + proxy.initializing = true; + + Cryptpad.whenRealtimeSyncs(result.realtime, function () { + Cryptpad.login(result.userHash, result.userName, function () { + if (sessionStorage.redirectTo) { + var h = sessionStorage.redirectTo; + var parser = document.createElement('a'); + parser.href = h; + if (parser.origin === window.location.origin) { + delete sessionStorage.redirectTo; + window.location.href = h; + return; + } } - } - window.location.href = '/drive/'; + window.location.href = '/drive/'; + }); }); }); }); From 1540ae3f6f669662f939a0892a1a10e879caaa5d Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 17 Feb 2017 15:16:30 +0100 Subject: [PATCH 02/11] Fix issue with null entries in Cryptpad_RECENTPADS --- www/common/cryptpad-common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index af5fca0f3..a18731c26 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -351,7 +351,7 @@ define([ title: pad[2] || hash && hash.slice(0,8), ctime: pad[1], }; - } else if (typeof(pad) === 'object') { + } else if (pad && typeof(pad) === 'object') { if (!pad.ctime) { pad.ctime = pad.atime; } if (!pad.title) { pad.href.replace(/#(.*)$/, function (x, hash) { @@ -367,7 +367,7 @@ define([ } else { console.error("[Cryptpad.migrateRecentPads] pad had unexpected value"); console.log(pad); - return {}; + return; } }).filter(function (x) { return x; }); }; From c17f28e5fe06651d5ff7aca7f917dfb92194b56e Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 17 Feb 2017 15:39:34 +0100 Subject: [PATCH 03/11] Fix race condition #2 --- www/code/main.js | 14 +++++++------- www/pad/main.js | 5 +++++ www/poll/main.js | 4 ++++ www/slide/main.js | 5 +++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index e9dd9d8e4..869a0f8e5 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -22,15 +22,15 @@ define([ Cryptpad: Cryptpad, }; - Cryptpad.styleAlerts(); - Cryptpad.addLoadingScreen(); + $(function () { + Cryptpad.styleAlerts(); + Cryptpad.addLoadingScreen(); - var ifrw = module.ifrw = $('#pad-iframe')[0].contentWindow; - var stringify = function (obj) { - return JSONSortify(obj); - }; + var ifrw = module.ifrw = $('#pad-iframe')[0].contentWindow; + var stringify = function (obj) { + return JSONSortify(obj); + }; - $(function () { var toolbar; var secret = Cryptpad.getSecrets(); diff --git a/www/pad/main.js b/www/pad/main.js index 15a5abb47..7ca731462 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -21,6 +21,9 @@ define([ Visible, Notify) { var $ = window.jQuery; var saveAs = window.saveAs; + + $(function () { + var ifrw = $('#pad-iframe')[0].contentWindow; var Ckeditor; // to be initialized later... var DiffDom = window.diffDOM; @@ -814,4 +817,6 @@ define([ }; $(first); + + }); }); diff --git a/www/poll/main.js b/www/poll/main.js index 85ebec555..2af07f0e0 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -15,6 +15,8 @@ define([ ], function (Config, Messages, TextPatcher, Listmap, Crypto, Cryptpad, Hyperjson, Renderer, Toolbar, Visible, Notify) { var $ = window.jQuery; + $(function () { + var unlockHTML = ''; var lockHTML = ''; var HIDE_INTRODUCTION_TEXT = "hide_poll_text"; @@ -786,5 +788,7 @@ define([ onConnectError(); } }); + + }); }); diff --git a/www/slide/main.js b/www/slide/main.js index f9e9bd8c2..25c3b22b2 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -28,9 +28,7 @@ define([ var SLIDE_BACKCOLOR_ID = "cryptpad-backcolor"; var SLIDE_COLOR_ID = "cryptpad-color"; - Cryptpad.styleAlerts(); - Cryptpad.addLoadingScreen(); var stringify = function (obj) { return JSONSortify(obj); @@ -45,6 +43,9 @@ define([ }; $(function () { + Cryptpad.styleAlerts(); + Cryptpad.addLoadingScreen(); + var ifrw = module.ifrw = $('#pad-iframe')[0].contentWindow; var toolbar; From a6497f7a5217970da525b3f8a9345c047936d230 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 17 Feb 2017 16:56:59 +0100 Subject: [PATCH 04/11] Add a way to show the drive tips again --- customize.dist/translations/messages.fr.js | 4 +++- customize.dist/translations/messages.js | 3 +++ www/settings/main.js | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index c6a301445..ef009add6 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -317,7 +317,9 @@ define(function () { "Êtes-vous sûr de vouloir continuer ?
" + "Tapez “I love CryptPad” pour confirmer."; out.settings_resetDone = "Votre drive est désormais vide!"; - + out.settings_resetTips = "Astuces et informations dans CryptDrive"; + out.settings_resetTipsButton = "Réinitialiser les astuces visibles dans CryptDrive"; + out.settings_resetTipsDone = "Toutes les astuces sont de nouveau visibles."; // index.html diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 0958ad301..2529124b5 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -318,6 +318,9 @@ define(function () { "Are you sure you want to continue?
" + "Type “I love CryptPad” to confirm."; out.settings_resetDone = "Your drive is now empty!"; + out.settings_resetTips = "Tips in CryptDrive"; + out.settings_resetTipsButton = "Reset the available tips in CryptDrive"; + out.settings_resetTipsDone = "All the tips are now visible again."; // index.html diff --git a/www/settings/main.js b/www/settings/main.js index 6587cb4f0..e8e145fb3 100644 --- a/www/settings/main.js +++ b/www/settings/main.js @@ -95,7 +95,24 @@ define([ return $div; }; + var createResetTips = function () { + var $div = $('
', {'class': 'resetTips'}); + var $label = $('