From cb2fa144ef3040e5ed95fb0b7c6d8849460be15e Mon Sep 17 00:00:00 2001 From: Splines Date: Wed, 6 Dec 2023 00:32:48 +0100 Subject: [PATCH] Fix <= logical bug (registration threshold) --- app/controllers/registrations_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 0df007563..be7b5e3a6 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -72,13 +72,14 @@ def after_sign_up_path_for(_resource) def check_registration_limit timeframe = (ENV["MAMPF_REGISTRATION_TIMEFRAME"] || 15).to_i.minutes threshold_date = DateTime.now - timeframe - new_users = User.where( + num_new_registrations = User.where( "users.confirmed_at is NULL and users.created_at > '#{threshold_date}'" ).count - max_users = (ENV["MAMPF_MAX_REGISTRATION_PER_TIMEFRAME"] || 40).to_i - return if new_users > max_users + max_registrations = (ENV["MAMPF_MAX_REGISTRATION_PER_TIMEFRAME"] || 40).to_i + return if num_new_registrations <= max_registrations + # Current number of new registrations is too high self.resource = resource_class.new(devise_parameter_sanitizer.sanitize(:sign_up)) resource.validate # Look for any other validation errors besides reCAPTCHA set_flash_message(:alert, :too_many_registrations)