From 5b8b651b67beee610177b21d0070aaac748faacb Mon Sep 17 00:00:00 2001 From: Mac Siri Date: Fri, 14 May 2021 11:43:49 -0400 Subject: [PATCH] Allow sign up without email smtp config (#13650) --- app/controllers/registrations_controller.rb | 7 ++++++- app/models/site_config.rb | 4 ++++ app/models/user.rb | 4 ++++ config/environments/production.rb | 2 +- spec/system/authentication/user_logs_in_with_email_spec.rb | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 1a3b05d81..fa061bd73 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -31,7 +31,12 @@ class RegistrationsController < Devise::RegistrationsController yield resource if block_given? if resource.persisted? update_first_user_permissions(resource) - redirect_to "/confirm-email?email=#{CGI.escape(resource.email)}" + if SiteConfig.smtp_enabled? + redirect_to confirm_email_path(email: resource.email) + else + sign_in(resource) + redirect_to root_path + end else render action: "by_email" end diff --git a/app/models/site_config.rb b/app/models/site_config.rb index 6e6e99788..06e394a38 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -224,4 +224,8 @@ class SiteConfig < RailsSettings::Base def self.get_default(field) get_field(field)[:default] end + + def self.smtp_enabled? + Rails.configuration.action_mailer.perform_deliveries + end end diff --git a/app/models/user.rb b/app/models/user.rb index 2cbe3edd2..94027fe58 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -694,4 +694,8 @@ class User < ApplicationRecord def strip_payment_pointer self.payment_pointer = payment_pointer.strip if payment_pointer end + + def confirmation_required? + SiteConfig.smtp_enabled? + end end diff --git a/config/environments/production.rb b/config/environments/production.rb index efa428577..9b39682ff 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -127,7 +127,7 @@ Rails.application.configure do protocol = ENV["APP_PROTOCOL"] || "http://" config.action_mailer.delivery_method = :smtp - config.action_mailer.perform_deliveries = true + config.action_mailer.perform_deliveries = ENV["SMTP_PASWORD"].present? || ENV["SENDGRID_API_KEY"].present? config.action_mailer.default_url_options = { host: protocol + ENV["APP_DOMAIN"].to_s } ActionMailer::Base.smtp_settings = if ENV["SENDGRID_API_KEY"].present? { diff --git a/spec/system/authentication/user_logs_in_with_email_spec.rb b/spec/system/authentication/user_logs_in_with_email_spec.rb index a19a74dab..7a8fe8a12 100644 --- a/spec/system/authentication/user_logs_in_with_email_spec.rb +++ b/spec/system/authentication/user_logs_in_with_email_spec.rb @@ -7,6 +7,7 @@ RSpec.describe "Authenticating with Email" do before do allow(Settings::Authentication).to receive(:allow_email_password_registration).and_return(true) allow(Settings::Authentication).to receive(:allow_email_password_login).and_return(true) + allow(SiteConfig).to receive(:smtp_enabled?).and_return(true) # rubocop:disable RSpec/AnyInstance allow_any_instance_of(ProfileImageUploader).to receive(:download!) # rubocop:enable RSpec/AnyInstance