From a9de712eeddbc59085de1acad9587eb15f8e8b35 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 19 Mar 2018 16:08:10 -0400 Subject: [PATCH] FIX: not found message when trying to log in with a link, even though the email with the link was successfully sent --- .../discourse/controllers/login.js.es6 | 6 +-- .../acceptance/login-with-email-test.js.es6 | 38 ++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/login.js.es6 b/app/assets/javascripts/discourse/controllers/login.js.es6 index e051bd190a..f5cc976902 100644 --- a/app/assets/javascripts/discourse/controllers/login.js.es6 +++ b/app/assets/javascripts/discourse/controllers/login.js.es6 @@ -236,10 +236,10 @@ export default Ember.Controller.extend(ModalFunctionality, { const loginName = escapeExpression(this.get('loginName')); const isEmail = loginName.match(/@/); let key = `email_login.complete_${isEmail ? 'email' : 'username'}`; - if (data.user_found) { - this.flash(I18n.t(`${key}_found`, { email: loginName, username: loginName })); - } else { + if (data.user_found === false) { this.flash(I18n.t(`${key}_not_found`, { email: loginName, username: loginName }), 'error'); + } else { + this.flash(I18n.t(`${key}_found`, { email: loginName, username: loginName })); } }).catch(e => { this.flash(extractError(e), 'error'); diff --git a/test/javascripts/acceptance/login-with-email-test.js.es6 b/test/javascripts/acceptance/login-with-email-test.js.es6 index beaa78dd0b..ecd8f161d7 100644 --- a/test/javascripts/acceptance/login-with-email-test.js.es6 +++ b/test/javascripts/acceptance/login-with-email-test.js.es6 @@ -17,7 +17,7 @@ acceptance("Login with email", { }; server.post('/u/email-login', () => { // eslint-disable-line no-undef - return response({ "user_found": userFound }); + return response({ "success": "OK", "user_found": userFound }); }); } }); @@ -115,3 +115,39 @@ QUnit.test("logging in via email (button)", assert => { ); }); }); + +acceptance("Login with email", { + settings: { + enable_local_logins_via_email: true, + enable_facebook_logins: true, + hide_email_address_taken: true + }, + beforeEach() { + const response = object => { + return [ + 200, + { "Content-Type": "application/json" }, + object + ]; + }; + + server.post('/u/email-login', () => { // eslint-disable-line no-undef + return response({ "success": "OK" }); + }); + } +}); + +QUnit.test("login via email with hide_email_address_taken enabled", assert => { + visit("/"); + click("header .login-button"); + fillIn("#login-account-name", 'someuser@example.com'); + click('.login-with-email-button'); + + andThen(() => { + assert.equal( + find(".alert-success").html().trim(), + I18n.t('email_login.complete_email_found', { email: 'someuser@example.com' }), + 'it should display the success message for any email address' + ); + }); +});