Skip to content

Commit

Permalink
Fix <= logical bug (registration threshold)
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Dec 5, 2023
1 parent eb2189b commit cb2fa14
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cb2fa14

Please sign in to comment.