From a5d689e76cc8357fe64c57c5474d25fbdc8626a6 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Fri, 27 Jul 2018 20:27:40 +0200 Subject: [PATCH] Do not allow spam users to be created --- app/validators/screen_name_validator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/validators/screen_name_validator.rb b/app/validators/screen_name_validator.rb index 4191dca4..ad157d48 100644 --- a/app/validators/screen_name_validator.rb +++ b/app/validators/screen_name_validator.rb @@ -3,10 +3,14 @@ class ScreenNameValidator < ActiveModel::EachValidator notifications inbox sign_in sign_up sidekiq moderation moderator mod administrator siteadmin site_admin help retro_spring retroospring retrosprlng niisding nllsding pixeidesu plxeldesu plxeidesu terms privacy) + FORBIDDEN_SCREEN_NAME_REGEXPS = [/wreciap\z/i] def validate_each(record, attribute, value) if FORBIDDEN_SCREEN_NAMES.include? value.downcase record.errors[attribute] << "Thou shalt not use this username! Please choose another one." end + if FORBIDDEN_SCREEN_NAME_REGEXPS.any? { |regexp| value.downcase =~ regexp } + record.errors[attribute] << "Registration is tempoarily disabled for new users." + end end end