Skip to content

A platform for community discussion. Free, open, simple.

FIX: Discourse Connect fixes for full page login (#29915)

Jan Cernika964e62cd8e2
diff --git a/app/assets/javascripts/discourse/app/controllers/login.js b/app/assets/javascripts/discourse/app/controllers/login.js
index 25ac5b110ef..11ece210557 100644
--- a/app/assets/javascripts/discourse/app/controllers/login.js
+++ b/app/assets/javascripts/discourse/app/controllers/login.js
@@ -116,8 +116,15 @@ export default class LoginPageController extends Controller {
return getURL("/u/admin-login");
}
+ get shouldTriggerRouteAction() {
+ return (
+ !this.siteSettings.experimental_full_page_login ||
+ this.siteSettings.enable_discourse_connect
+ );
+ }
+
@action
- showLoginPage() {
+ showFullPageLogin() {
this.showLogin = true;
}
diff --git a/app/assets/javascripts/discourse/app/controllers/signup.js b/app/assets/javascripts/discourse/app/controllers/signup.js
index f6c20c7a877..944fcefc8ff 100644
--- a/app/assets/javascripts/discourse/app/controllers/signup.js
+++ b/app/assets/javascripts/discourse/app/controllers/signup.js
@@ -54,12 +54,6 @@ export default class SignupPageController extends Controller.extend(
}
this.fetchConfirmationValue();
-
- if (this.skipConfirmation) {
- this.performAccountCreation().finally(() =>
- this.set("skipConfirmation", false)
- );
- }
}
@bind
@@ -342,6 +336,14 @@ export default class SignupPageController extends Controller.extend(
return this._hpPromise;
}
+ handleSkipConfirmation() {
+ if (this.skipConfirmation) {
+ this.performAccountCreation().finally(() =>
+ this.set("skipConfirmation", false)
+ );
+ }
+ }
+
performAccountCreation() {
if (
!this._challengeDate ||
diff --git a/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js b/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js
index 3cbe7b093e7..506178ab7ba 100644
--- a/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js
+++ b/app/assets/javascripts/discourse/app/instance-initializers/auth-complete.js
@@ -146,6 +146,7 @@ export default {
Object.keys(createAccountProps || {}).forEach((key) => {
signupController.set(key, createAccountProps[key]);
});
+ signupController.handleSkipConfirmation();
});
} else {
modal.show(CreateAccount, { model: createAccountProps });
diff --git a/app/assets/javascripts/discourse/app/routes/login.js b/app/assets/javascripts/discourse/app/routes/login.js
index e1acb0f0a83..4732bdfa2b2 100644
--- a/app/assets/javascripts/discourse/app/routes/login.js
+++ b/app/assets/javascripts/discourse/app/routes/login.js
@@ -11,7 +11,8 @@ export default class LoginRoute extends DiscourseRoute {
beforeModel() {
if (
!this.siteSettings.login_required &&
- !this.siteSettings.experimental_full_page_login
+ (!this.siteSettings.experimental_full_page_login ||
+ this.siteSettings.enable_discourse_connect)
) {
this.router
.replaceWith(`/${defaultHomepage()}`)
diff --git a/app/assets/javascripts/discourse/app/templates/login.hbs b/app/assets/javascripts/discourse/app/templates/login.hbs
index b04c4640238..cdcd7318c93 100644
--- a/app/assets/javascripts/discourse/app/templates/login.hbs
+++ b/app/assets/javascripts/discourse/app/templates/login.hbs
@@ -161,9 +161,9 @@
<DButton
@action={{if
- this.siteSettings.experimental_full_page_login
- this.showLoginPage
+ this.shouldTriggerRouteAction
(route-action "showLogin")
+ this.showFullPageLogin
}}
@icon="user"
@label="log_in"
diff --git a/spec/system/page_objects/modals/signup.rb b/spec/system/page_objects/modals/signup.rb
index 0dfacd68afe..bd4256d0c25 100644
--- a/spec/system/page_objects/modals/signup.rb
+++ b/spec/system/page_objects/modals/signup.rb
@@ -98,6 +98,18 @@ module PageObjects
has_valid_password?
end
+ def has_disabled_email?
+ find(".create-account-email").has_css?("input[disabled]")
+ end
+
+ def has_disabled_name?
+ find(".create-account__fullname").has_css?("input[disabled]")
+ end
+
+ def has_disabled_username?
+ find(".create-account__username").has_css?("input[disabled]")
+ end
+
def click_social_button(provider)
click(".btn-social.#{provider}")
end
diff --git a/spec/system/page_objects/pages/signup.rb b/spec/system/page_objects/pages/signup.rb
index 9f2c2e30245..b807faa82a0 100644
--- a/spec/system/page_objects/pages/signup.rb
+++ b/spec/system/page_objects/pages/signup.rb
@@ -98,6 +98,18 @@ module PageObjects
has_valid_password?
end
+ def has_disabled_email?
+ find(".create-account-email").has_css?("input[disabled]")
+ end
+
+ def has_disabled_name?
+ find(".create-account__fullname").has_css?("input[disabled]")
+ end
+
+ def has_disabled_username?
+ find(".create-account__username").has_css?("input[disabled]")
+ end
+
def click_social_button(provider)
click(".btn-social.#{provider}")
end
diff --git a/spec/system/social_authentication_spec.rb b/spec/system/social_authentication_spec.rb
index 54d8db1d49b..87ea8144590 100644
--- a/spec/system/social_authentication_spec.rb
+++ b/spec/system/social_authentication_spec.rb
@@ -171,6 +171,67 @@ shared_examples "social authentication scenarios" do |signup_page_object, login_
expect(page).to have_css(".header-dropdown-toggle.current-user")
end
end
+
+ # These tests use Google, but they should be the same for all providers
+
+ context "when opening the external auth from /login" do
+ before { SiteSetting.enable_google_oauth2_logins = true }
+ after { reset_omniauth_config(:google_oauth2) }
+
+ it "fills the signup form" do
+ mock_google_auth
+ visit("/")
+
+ signup_form.open.click_social_button("google_oauth2")
+ expect(signup_form).to be_open
+ expect(signup_form).to have_no_password_input
+ expect(signup_form).to have_valid_username
+ expect(signup_form).to have_valid_email
+ signup_form.click_create_account
+ expect(page).to have_css(".header-dropdown-toggle.current-user")
+ end
+ end
+
+ context "when overriding local fields" do
+ before do
+ SiteSetting.enable_google_oauth2_logins = true
+ SiteSetting.auth_overrides_name = true
+ SiteSetting.auth_overrides_username = true
+ end
+ after { reset_omniauth_config(:google_oauth2) }
+
+ it "fills the signup form and disables the inputs" do
+ mock_google_auth
+ visit("/")
+
+ signup_form.open.click_social_button("google_oauth2")
+ expect(signup_form).to be_open
+ expect(signup_form).to have_no_password_input
+ expect(signup_form).to have_valid_username
+ expect(signup_form).to have_valid_email
+ expect(signup_form).to have_disabled_username
+ expect(signup_form).to have_disabled_email
+ expect(signup_form).to have_disabled_name
+ signup_form.click_create_account
+ expect(page).to have_css(".header-dropdown-toggle.current-user")
+ end
+ end
+
+ context "when skipping the signup form" do
+ before do
+ SiteSetting.enable_google_oauth2_logins = true
+ SiteSetting.auth_skip_create_confirm = true
+ end
+ after { reset_omniauth_config(:google_oauth2) }
+
+ it "creates the account directly" do
+ mock_google_auth
+ visit("/")
+
+ signup_form.open.click_social_button("google_oauth2")
+ expect(page).to have_css(".header-dropdown-toggle.current-user")
+ end
+ end
end
context "when user exists" do