From 3aa03225c96cd8daf18c407d9bcf9cd88ec58efa Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 13 Feb 2017 11:09:30 +0100 Subject: [PATCH 1/2] Add a spinner when hashing the password and translate homepage --- customize.dist/main.js | 62 ++++++++++++--------- customize.dist/translations/messages.fr.js | 9 ++++ customize.dist/translations/messages.js | 7 ++- www/common/cryptpad-common.js | 4 +- www/login/main.js | 63 +++++++++++++--------- 5 files changed, 90 insertions(+), 55 deletions(-) diff --git a/customize.dist/main.js b/customize.dist/main.js index ac378e185..9397709aa 100644 --- a/customize.dist/main.js +++ b/customize.dist/main.js @@ -112,33 +112,43 @@ define([ }); $('button.login').click(function (e) { - loginReady(function () { - var uname = $uname.val(); - var passwd = $passwd.val(); - - Login.loginOrRegister(uname, passwd, false, function (err, result) { - if (!err) { - // successful validation and user already exists - // set user hash in localStorage and redirect to drive - localStorage.User_hash = result.userHash; - document.location.href = '/drive/'; - - return; - } - switch (err) { - case 'NO_SUCH_USER': - Cryptpad.alert('Invalid username or password. Try again, or sign up'); // XXX - break; - case 'INVAL_USER': - Cryptpad.alert('Username required'); // XXX - break; - case 'INVAL_PASS': - Cryptpad.alert('Password required'); // XXX - break; - default: // UNHANDLED ERROR - } + Cryptpad.addLoadingScreen(Messages.login_hashing); + // We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password + window.setTimeout(function () { + loginReady(function () { + var uname = $uname.val(); + var passwd = $passwd.val(); + Login.loginOrRegister(uname, passwd, false, function (err, result) { + if (!err) { + // successful validation and user already exists + // set user hash in localStorage and redirect to drive + Cryptpad.login(result.userHash, result.userName, function () { + document.location.href = '/drive/'; + }); + return; + } + 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); + } + }); }); - }); + }, 0); }); /* End Log in UI */ diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 89237f351..2a14e9370 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -282,6 +282,15 @@ define(function () { out.login_accessDrive = 'Accédez à votre drive'; out.login_orNoLogin = 'ou'; + out.login_noSuchUser = "Nom d'utilisateur ou mot de passe invalide. Veuillez vous inscrire ou réessayer."; + out.login_invalUser = "Nom d'utilisateur requis"; + out.login_invalPass = 'Mot de passe requis'; + out.login_unhandledError = "Une erreur inattendue s'est produite :("; + + out.register_importRecent = "Importer l'historique (Recommendé)"; + out.register_acceptTerms = "J'accepte les conditions d'utilisation"; + out.register_rememberPassword = "Je vais me souvenir de mes identifiants"; + // 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.'; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 286b4e9b7..942364b49 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -283,8 +283,13 @@ define(function () { out.login_accessDrive = 'Access your drive'; out.login_orNoLogin = 'or'; + out.login_noSuchUser = 'Invalid username or password. Try again, or sign up'; + out.login_invalUser = 'Username required'; + out.login_invalPass = 'Password required'; + out.login_unhandledError = 'An unexpected error occured :('; + out.register_importRecent = "Import pad history (Recommended)"; - out.register_acceptTerms = "I accept the terms"; + out.register_acceptTerms = "I accept the terms of use"; out.register_rememberPassword = "I will remember my login name and password"; // index.html diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index fc7bee587..6a8cc5875 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -734,7 +734,7 @@ define([ }; var LOADING = 'loading'; - common.addLoadingScreen = function () { + common.addLoadingScreen = function (loadingText) { if ($('#' + LOADING).length) { $('#' + LOADING).show(); return; @@ -744,7 +744,7 @@ define([ $container.append(''); var $spinner = $('
', {'class': 'spinnerContainer'}); var loadingSpinner = common.spinner($spinner).show(); - var $text = $('

').text(Messages.loading); + var $text = $('

').text(loadingText || Messages.loading); $container.append($spinner).append($text); $loading.append($container); $('body').append($loading); diff --git a/www/login/main.js b/www/login/main.js index 26f673cf2..7b2b8ca6f 100644 --- a/www/login/main.js +++ b/www/login/main.js @@ -12,6 +12,7 @@ define([ $(function () { var $main = $('#mainBlock'); + var Messages = Cryptpad.Messages; // Language selector var $sel = $('#language-selector'); @@ -63,33 +64,43 @@ define([ }); $('button.login').click(function (e) { - loginReady(function () { - var uname = $uname.val(); - var passwd = $passwd.val(); - - Login.loginOrRegister(uname, passwd, false, function (err, result) { - if (!err) { - // successful validation and user already exists - // set user hash in localStorage and redirect to drive - localStorage.User_hash = result.userHash; - document.location.href = '/drive/'; - - return; - } - switch (err) { - case 'NO_SUCH_USER': - Cryptpad.alert('Invalid username or password. Try again, or sign up'); // XXX - break; - case 'INVAL_USER': - Cryptpad.alert('Username required'); // XXX - break; - case 'INVAL_PASS': - Cryptpad.alert('Password required'); // XXX - break; - default: // UNHANDLED ERROR - } + Cryptpad.addLoadingScreen(Messages.login_hashing); + // We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password + window.setTimeout(function () { + loginReady(function () { + var uname = $uname.val(); + var passwd = $passwd.val(); + Login.loginOrRegister(uname, passwd, false, function (err, result) { + if (!err) { + // successful validation and user already exists + // set user hash in localStorage and redirect to drive + Cryptpad.login(result.userHash, result.userName, function () { + document.location.href = '/drive/'; + }); + return; + } + 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); + } + }); }); - }); + }, 0); }); }); }); From bff9d05210ee0f2fb47a56f003f612df9cafd30d Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 13 Feb 2017 11:15:30 +0100 Subject: [PATCH 2/2] Make sure the login_name is in the object --- customize.dist/main.js | 3 +++ www/login/main.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/customize.dist/main.js b/customize.dist/main.js index 9397709aa..766977f0d 100644 --- a/customize.dist/main.js +++ b/customize.dist/main.js @@ -122,6 +122,9 @@ define([ if (!err) { // successful validation and user already exists // set user hash in localStorage and redirect to drive + if (result.proxy && !result.proxy.login_name) { + result.proxy.login_name = result.userName; + } Cryptpad.login(result.userHash, result.userName, function () { document.location.href = '/drive/'; }); diff --git a/www/login/main.js b/www/login/main.js index 7b2b8ca6f..a6273b469 100644 --- a/www/login/main.js +++ b/www/login/main.js @@ -74,6 +74,9 @@ define([ if (!err) { // successful validation and user already exists // set user hash in localStorage and redirect to drive + if (result.proxy && !result.proxy.login_name) { + result.proxy.login_name = result.userName; + } Cryptpad.login(result.userHash, result.userName, function () { document.location.href = '/drive/'; });