diff --git a/app/assets/javascripts/discourse/components/login-buttons.js.es6 b/app/assets/javascripts/discourse/components/login-buttons.js.es6 index 3351424b8df..c9fd5109c48 100644 --- a/app/assets/javascripts/discourse/components/login-buttons.js.es6 +++ b/app/assets/javascripts/discourse/components/login-buttons.js.es6 @@ -5,7 +5,10 @@ export default Ember.Component.extend({ elementId: "login-buttons", classNameBindings: ["hidden"], - hidden: Ember.computed.equal("buttons.length", 0), + @computed("buttons.length", "showLoginWithEmailLink") + hidden(buttonsCount, showLoginWithEmailLink) { + return buttonsCount === 0 && !showLoginWithEmailLink; + }, @computed buttons() { diff --git a/app/assets/javascripts/discourse/controllers/login.js.es6 b/app/assets/javascripts/discourse/controllers/login.js.es6 index 2a52c8f7c03..d2d1b4e4d1d 100644 --- a/app/assets/javascripts/discourse/controllers/login.js.es6 +++ b/app/assets/javascripts/discourse/controllers/login.js.es6 @@ -70,17 +70,9 @@ export default Ember.Controller.extend(ModalFunctionality, { return this.get("loggingIn") || this.get("authenticate"); }.property("loggingIn", "authenticate"), - @computed("canLoginLocalWithEmail", "loginName", "processingEmailLink") - showLoginWithEmailLink( - canLoginLocalWithEmail, - loginName, - processingEmailLink - ) { - return ( - canLoginLocalWithEmail && - !Ember.isEmpty(loginName) && - !processingEmailLink - ); + @computed("canLoginLocalWithEmail", "processingEmailLink") + showLoginWithEmailLink(canLoginLocalWithEmail, processingEmailLink) { + return canLoginLocalWithEmail && !processingEmailLink; }, actions: { diff --git a/app/assets/javascripts/discourse/templates/components/login-buttons.hbs b/app/assets/javascripts/discourse/templates/components/login-buttons.hbs index bdd430c4e7a..5289a927df0 100644 --- a/app/assets/javascripts/discourse/templates/components/login-buttons.hbs +++ b/app/assets/javascripts/discourse/templates/components/login-buttons.hbs @@ -2,7 +2,7 @@ {{/each}} -{{#if canLoginLocalWithEmail}} +{{#if showLoginWithEmailLink}} {{d-button action="emailLogin" label="email_login.button_label" diff --git a/app/assets/javascripts/discourse/templates/mobile/modal/login.hbs b/app/assets/javascripts/discourse/templates/mobile/modal/login.hbs index 5651a9b5930..ff8e577885b 100644 --- a/app/assets/javascripts/discourse/templates/mobile/modal/login.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/modal/login.hbs @@ -2,7 +2,7 @@ {{#d-modal-body title="login.title" class="login-modal"}} {{#if showLoginButtons}} {{login-buttons - canLoginLocalWithEmail=canLoginLocalWithEmail + showLoginWithEmailLink=showLoginWithEmailLink processingEmailLink=processingEmailLink emailLogin='emailLogin' externalLogin='externalLogin'}} @@ -20,16 +20,6 @@ {{text-field value=loginName type="email" placeholderKey="login.email_placeholder" id="login-account-name" autocorrect="off" autocapitalize="off"}} - {{#if showLoginWithEmailLink}} - - - - - {{i18n 'email_login.link_label'}} - - - - {{/if}} diff --git a/app/assets/javascripts/discourse/templates/modal/login.hbs b/app/assets/javascripts/discourse/templates/modal/login.hbs index fdf3034c63d..57a0bb7ffd5 100644 --- a/app/assets/javascripts/discourse/templates/modal/login.hbs +++ b/app/assets/javascripts/discourse/templates/modal/login.hbs @@ -8,13 +8,6 @@ {{text-field value=loginName placeholderKey="login.email_placeholder" id="login-account-name" autocorrect="off" autocapitalize="off" autofocus="autofocus"}} - - {{#if showLoginWithEmailLink}} - - {{i18n 'email_login.link_label'}} - - {{/if}} - @@ -33,10 +26,9 @@ {{/second-factor-form}} {{/if}} - {{#if showLoginButtons}} {{login-buttons - canLoginLocalWithEmail=canLoginLocalWithEmail + showLoginWithEmailLink=showLoginWithEmailLink processingEmailLink=processingEmailLink emailLogin='emailLogin' externalLogin='externalLogin'}} diff --git a/test/javascripts/acceptance/login-with-email-and-hide-email-address-taken-test.js.es6 b/test/javascripts/acceptance/login-with-email-and-hide-email-address-taken-test.js.es6 new file mode 100644 index 00000000000..faa51b87400 --- /dev/null +++ b/test/javascripts/acceptance/login-with-email-and-hide-email-address-taken-test.js.es6 @@ -0,0 +1,37 @@ +import { acceptance } from "helpers/qunit-helpers"; + +acceptance("Login with email - hide email address taken", { + settings: { + enable_local_logins_via_email: true, + hide_email_address_taken: true + }, + beforeEach() { + const response = object => { + return [200, { "Content-Type": "application/json" }, object]; + }; + + // prettier-ignore + server.post("/u/email-login", () => { // eslint-disable-line no-undef + return response({ success: "OK" }); + }); + } +}); + +QUnit.test("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" + ); + }); +}); diff --git a/test/javascripts/acceptance/login-with-email-and-no-social-logins-test.js.es6 b/test/javascripts/acceptance/login-with-email-and-no-social-logins-test.js.es6 new file mode 100644 index 00000000000..7fc715a6c8a --- /dev/null +++ b/test/javascripts/acceptance/login-with-email-and-no-social-logins-test.js.es6 @@ -0,0 +1,35 @@ +import { acceptance } from "helpers/qunit-helpers"; + +acceptance("Login with email - no social logins", { + settings: { + enable_local_logins_via_email: true + }, + beforeEach() { + const response = object => { + return [200, { "Content-Type": "application/json" }, object]; + }; + + // prettier-ignore + server.post("/u/email-login", () => { // eslint-disable-line no-undef + return response({ success: "OK" }); + }); + } +}); + +QUnit.test("with login with email enabled", assert => { + visit("/"); + click("header .login-button"); + + andThen(() => { + assert.ok(exists(".login-with-email-button")); + }); +}); + +QUnit.test("with login with email disabled", assert => { + visit("/"); + click("header .login-button"); + + andThen(() => { + assert.notOk(find(".login-buttons").is(":visible")); + }); +}); diff --git a/test/javascripts/acceptance/login-with-email-disabled-test.js.es6 b/test/javascripts/acceptance/login-with-email-disabled-test.js.es6 new file mode 100644 index 00000000000..28b59a2f2c3 --- /dev/null +++ b/test/javascripts/acceptance/login-with-email-disabled-test.js.es6 @@ -0,0 +1,25 @@ +import { acceptance } from "helpers/qunit-helpers"; + +acceptance("Login with email disabled", { + settings: { + enable_local_logins_via_email: false, + enable_facebook_logins: true + } +}); + +QUnit.test("with email button", assert => { + visit("/"); + click("header .login-button"); + + andThen(() => { + assert.ok( + exists(".btn-social.facebook"), + "it displays the facebook login button" + ); + + assert.notOk( + exists(".login-with-email-button"), + "it displays the login with email button" + ); + }); +}); diff --git a/test/javascripts/acceptance/login-with-email-test.js.es6 b/test/javascripts/acceptance/login-with-email-test.js.es6 index d7e6c4342c7..3d56fea32eb 100644 --- a/test/javascripts/acceptance/login-with-email-test.js.es6 +++ b/test/javascripts/acceptance/login-with-email-test.js.es6 @@ -19,20 +19,24 @@ acceptance("Login with email", { } }); -QUnit.test("logging in via email (link)", assert => { +QUnit.test("with email button", assert => { visit("/"); click("header .login-button"); andThen(() => { - assert.notOk( - exists(".login-with-email-link"), - "it displays the link only when field is filled" + assert.ok( + exists(".btn-social.facebook"), + "it displays the facebook login button" + ); + + assert.ok( + exists(".login-with-email-button"), + "it displays the login with email button" ); - userFound = false; }); fillIn("#login-account-name", "someuser"); - click(".login-with-email-link"); + click(".login-with-email-button"); andThen(() => { assert.equal( @@ -45,7 +49,7 @@ QUnit.test("logging in via email (link)", assert => { }); fillIn("#login-account-name", "someuser@gmail.com"); - click(".login-with-email-link"); + click(".login-with-email-button"); andThen(() => { assert.equal( @@ -63,7 +67,7 @@ QUnit.test("logging in via email (link)", assert => { userFound = true; }); - click(".login-with-email-link"); + click(".login-with-email-button"); andThen(() => { assert.equal( @@ -78,7 +82,7 @@ QUnit.test("logging in via email (link)", assert => { visit("/"); click("header .login-button"); fillIn("#login-account-name", "someuser@gmail.com"); - click(".login-with-email-link"); + click(".login-with-email-button"); andThen(() => { assert.equal( @@ -96,71 +100,3 @@ QUnit.test("logging in via email (link)", assert => { userFound = false; }); }); - -QUnit.test("logging in via email (button)", assert => { - visit("/"); - click("header .login-button"); - click(".login-with-email-button"); - - andThen(() => { - assert.equal( - find(".alert-error").html(), - I18n.t("login.blank_username"), - "it should display an error for blank username" - ); - }); - - andThen(() => { - userFound = true; - }); - - fillIn("#login-account-name", "someuser"); - click(".login-with-email-button"); - - andThen(() => { - assert.equal( - find(".alert-success") - .html() - .trim(), - I18n.t("email_login.complete_username_found", { username: "someuser" }), - "it should display a success message for a valid username" - ); - }); -}); - -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]; - }; - - // prettier-ignore - 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" - ); - }); -});