diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 27d64db9b..33a1cd41f 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -125,3 +125,15 @@ label { flex-direction: column; gap: var(--su-4); } + +.admin-config-checkmark { + width: var(--su-4); + height: var(--su-4); + background-color: var(--accent-success); + border-radius: 100%; + color: var(--base-inverted); +} + +.cursor-disabled { + cursor: not-allowed; +} diff --git a/app/controllers/admin/configs_controller.rb b/app/controllers/admin/configs_controller.rb index 7dfff7fc4..123af1bc4 100644 --- a/app/controllers/admin/configs_controller.rb +++ b/app/controllers/admin/configs_controller.rb @@ -118,8 +118,7 @@ module Admin facebook_key facebook_secret invite_only_mode - allow_email_password_registration - allow_email_password_login + allow_both_email_signup_and_login require_captcha_for_email_password_registration primary_brand_color_hex spam_trigger_terms @@ -153,6 +152,8 @@ module Admin end end + toggle_email_password_authentication + redirect_to admin_config_path, notice: "Site configuration was successfully updated." end @@ -211,6 +212,17 @@ module Admin config[:credit_prices_in_cents]&.transform_values!(&:to_i) end + def toggle_email_password_authentication + if SiteConfig.allow_both_email_signup_and_login + SiteConfig.allow_email_password_registration = true + SiteConfig.allow_email_password_login = true + else + SiteConfig.allow_email_password_registration = false + SiteConfig.allow_email_password_login = false + SiteConfig.invite_only_mode = false + end + end + # Validations def brand_contrast_too_low hex = params.dig(:site_config, :primary_brand_color_hex) diff --git a/app/helpers/authentication_helper.rb b/app/helpers/authentication_helper.rb index c62dab3d3..a96a5130b 100644 --- a/app/helpers/authentication_helper.rb +++ b/app/helpers/authentication_helper.rb @@ -32,4 +32,24 @@ module AuthenticationHelper def waiting_on_first_user? SiteConfig.waiting_on_first_user end + + def disable_email_tooltip_class + SiteConfig.invite_only_mode || authentication_enabled_providers.none? ? "crayons-tooltip" : "" + end + + def disable_email_tooltip_content + SiteConfig.invite_only_mode || authentication_enabled_providers.none? ? disable_email_auth_tooltip_text : "" + end + + def disable_button_class + SiteConfig.invite_only_mode || authentication_enabled_providers.none? ? "disabled" : "" + end + + def disable_email_auth_tooltip_text + if SiteConfig.invite_only_mode + "You cannot do this until you disable Invite Only Mode" + elsif authentication_enabled_providers.none? + "You cannot do this until you enable at least one other registration option" + end + end end diff --git a/app/javascript/admin/controllers/config_controller.js b/app/javascript/admin/controllers/config_controller.js index d7b3fd304..47a39ce9f 100644 --- a/app/javascript/admin/controllers/config_controller.js +++ b/app/javascript/admin/controllers/config_controller.js @@ -1,11 +1,63 @@ import { Controller } from 'stimulus'; const recaptchaFields = document.querySelector('#recaptchaContainer'); +const emailSigninAndLoginCheckbox = document.querySelector( + '#email-signup-and-login-checkbox', +); +const emailAuthSettingsSection = document.querySelector( + '#email-auth-settings-section', +); +const modalAnchor = document.querySelector('.admin-config-modal-anchor'); +const emailAuthModalTitle = 'Disable email address registration'; +// TODO: Remove the sentence "You must update site config to save this action!" +// once we build more robust flow for Admin/Config +const emailAuthModalBody = + '
If you disable email address as a registration option, people cannot create an account with their email address.
However, people who have already created an account using their email address can continue to login.
You must update site config to save this action!
'; + +const adminConfigModal = ( + title, + body, + confirmBtnText, + confirmBtnAction, + cancelBtnText, + cancelBtnAction, +) => ` +${title}
+ +- <%= Constants::SiteConfig::DETAILS[:authentication_providers][:description] %> -
- <%= select_tag "site_config[authentication_providers]", - options_from_collection_for_select( - authentication_available_providers, - :provider_name, - :official_name, - authentication_enabled_providers.map(&:provider_name), - ), - multiple: true, - class: "form-control selectpicker", - data: { target: "config.authenticationProviders" } %> -+ How can people create an account on your community? +
- Email address and password -
+"> + Email address +
+ <% if SiteConfig.allow_both_email_signup_and_login %> ++ <%= Constants::SiteConfig::DETAILS[:authentication_providers][:description] %> +
+ <%= select_tag "site_config[authentication_providers]", + options_from_collection_for_select( + authentication_available_providers, + :provider_name, + :official_name, + authentication_enabled_providers.map(&:provider_name), + ), + multiple: true, + class: "form-control selectpicker", + data: { target: "config.authenticationProviders" } %> +