From 1ab4fd79520a72ec08395b8fbebaeabd63370e2a Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 30 Aug 2019 16:05:04 +0200 Subject: [PATCH] advise users against using their emails as their username --- customize.dist/credential.js | 6 ++++++ www/common/translations/messages.json | 4 ++++ www/register/main.js | 25 +++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/customize.dist/credential.js b/customize.dist/credential.js index d1d88bd97..cdbd835c5 100644 --- a/customize.dist/credential.js +++ b/customize.dist/credential.js @@ -8,6 +8,12 @@ define([ Cred.MINIMUM_PASSWORD_LENGTH = typeof(AppConfig.minimumPasswordLength) === 'number'? AppConfig.minimumPasswordLength: 8; + // https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript + Cred.isEmail = function (email) { + var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return re.test(String(email).toLowerCase()); + }; + Cred.isLongEnoughPassword = function (passwd) { return passwd.length >= Cred.MINIMUM_PASSWORD_LENGTH; }; diff --git a/www/common/translations/messages.json b/www/common/translations/messages.json index a021962f9..5ea3b8cd4 100644 --- a/www/common/translations/messages.json +++ b/www/common/translations/messages.json @@ -436,6 +436,10 @@ "register_cancel": "Go back", "register_warning": "Zero Knowledge means that we can't recover your data if you lose your password.", "register_alreadyRegistered": "This user already exists, do you want to log in?", + "register_emailWarning0": "It looks like you submitted your email as your username.", + "register_emailWarning1": "You can do that if you want, but it won't be sent to our server.", + "register_emailWarning2": "You won't be able to reset your password using your email as you can with many other services.", + "register_emailWarning3": "If you understand and would like to use your email for your username anyway, click OK.", "settings_cat_account": "Account", "settings_cat_drive": "CryptDrive", "settings_cat_cursor": "Cursor", diff --git a/www/register/main.js b/www/register/main.js index d93726f9d..4931efa3b 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -54,7 +54,9 @@ define([ var registering = false; var test; - $register.click(function () { + var I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME = false; + + var registerClick = function () { var uname = $uname.val(); var passwd = $passwd.val(); var confirmPassword = $confirm.val(); @@ -62,6 +64,23 @@ define([ var shouldImport = $checkImport[0].checked; var doesAccept = $checkAcceptTerms[0].checked; + if (Cred.isEmail(uname) && !I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME) { + var warning = [ + Messages.register_emailWarning0, + Messages.register_emailWarning1, + Messages.register_emailWarning2, + Messages.register_emailWarning3, + ].join('

'); + + Feedback.send("EMAIL_USERNAME_WARNING", true); + + return void UI.confirm(warning, function (yes) { + if (!yes) { return; } + I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME = true; + registerClick(); + }, {}, true); + } + /* basic validation */ if (!Cred.isLongEnoughPassword(passwd)) { var warning = Messages._getKey('register_passwordTooShort', [ @@ -104,7 +123,9 @@ define([ }, }, true); }, 150); - }); + }; + + $register.click(registerClick); var clickRegister = Util.notAgainForAnother(function () { $register.click();