From 19bdbb12b531ca8e79e310f3e231cc153191a730 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Wed, 19 Jun 2024 18:22:20 +0100 Subject: [PATCH] Disable signup in production --- .env.development | 1 + .env.test | 1 + .gitignore | 2 ++ Gemfile | 1 + Gemfile.lock | 2 ++ app/controllers/users_controller.rb | 4 ++++ app/views/layouts/application.html.erb | 4 +++- config/database.yml | 4 +++- config/deploy.yml | 1 + config/environments/production.rb | 2 +- todo.md | 1 - 11 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .env.development create mode 100644 .env.test diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..c664f31 --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +ENABLE_SIGNUP=true diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..c664f31 --- /dev/null +++ b/.env.test @@ -0,0 +1 @@ +ENABLE_SIGNUP=true diff --git a/.gitignore b/.gitignore index 5fb66c9..7a97e31 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ # Ignore all environment files (except templates). /.env* !/.env*.erb +!/.env.development +!/.env.test # Ignore all logfiles and tempfiles. /log/* diff --git a/Gemfile b/Gemfile index 8b3fc29..4134b9a 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem "active_storage_validations" group :development, :test do gem "debug", platforms: %i[ mri windows ] + gem "dotenv" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 1a3422c..8050c1c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,7 @@ GEM debug (1.9.2) irb (~> 1.10) reline (>= 0.3.8) + dotenv (3.1.2) drb (2.2.1) erubi (1.12.0) et-orbi (1.2.11) @@ -330,6 +331,7 @@ DEPENDENCIES bootsnap capybara debug + dotenv image_processing (~> 1.2) importmap-rails jbuilder diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1bc8967..c0a9815 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,10 +6,14 @@ class UsersController < ApplicationController before_action :ensure_self, only: [ :edit, :update ] def new + redirect_to :root and return unless ActiveModel::Type::Boolean.new.cast(ENV.fetch("ENABLE_SIGNUP") { false }) + @user = User.new end def create + redirect_to :root and return unless ActiveModel::Type::Boolean.new.cast(ENV.fetch("ENABLE_SIGNUP") { false }) + @user = User.new(new_user_params) if @user.save token = @user.generate_token_for(:email_verification) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d844ccd..f8210bf 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,7 +28,9 @@ <% end %> <% else %>
  • <%= link_to t("log_in"), login_path %>
  • -
  • <%= link_to t("sign_up"), new_user_path %>
  • + <% if ActiveModel::Type::Boolean.new.cast(ENV.fetch("ENABLE_SIGNUP") { false } ) %> +
  • <%= link_to t("sign_up"), new_user_path %>
  • + <% end %> <% end %> diff --git a/config/database.yml b/config/database.yml index 40b4f64..83bc75d 100644 --- a/config/database.yml +++ b/config/database.yml @@ -5,16 +5,18 @@ default: &default timeout: 5000 host: <%= ENV.fetch("DB_HOST") { "localhost" } %> username: <%= ENV.fetch("POSTGRES_USER") { "postgres" } %> - password: <%= ENV.fetch("POSTGRES_PASSWORD") { "postgres" } %> development: <<: *default database: tabletop_companion_development + password: postgres test: <<: *default database: tabletop_companion_test + password: postgres production: <<: *default database: tabletop_companion_production + password: <%= ENV.fetch("POSTGRES_PASSWORD") { "postgres" } %> diff --git a/config/deploy.yml b/config/deploy.yml index d94f463..9ea364c 100644 --- a/config/deploy.yml +++ b/config/deploy.yml @@ -43,6 +43,7 @@ env: clear: APPLICATION_HOST: ttcompanion.com DB_HOST: ttcompanion-postgres + ENABLE_SIGNUP: false RAILS_LOG_TO_STDOUT: true RAILS_SERVE_STATIC_FILES: true secret: diff --git a/config/environments/production.rb b/config/environments/production.rb index 28cc01f..285c7c3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -78,7 +78,7 @@ Rails.application.configure do config.action_mailer.smtp_settings = { address: "smtp.eu.mailgun.org", port: 587, - domain: ENV.fetch("APPLICATION_HOST"), + domain: "ttcompanion.com", username: "postmaster@mail.ttcompanion.com", password: Rails.application.credentials.dig(:mailgun, :password), } diff --git a/todo.md b/todo.md index c132427..e573fcb 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,4 @@ - set up email in prod -- disallow unverified accounts - request invite - don't move down/up top/bottom features - auto save text fields