Retrospring/app/validators/screen_name_validator.rb

15 lines
957 B
Ruby
Raw Normal View History

2022-01-22 12:32:45 -08:00
# frozen_string_literal: true
class ScreenNameValidator < ActiveModel::EachValidator
2022-01-22 12:32:45 -08:00
FORBIDDEN_SCREEN_NAMES = %w[justask_admin retrospring_admin admin justask retrospring about public
notifications inbox sign_in sign_up sidekiq moderation moderator mod administrator
2022-01-22 12:32:45 -08:00
siteadmin site_admin help retro_spring retroospring retrosprlng niisding nllsding
pixeidesu plxeldesu plxeidesu terms privacy linkfilter feedback].freeze
FORBIDDEN_SCREEN_NAME_REGEXPS = [/wreciap\z/i].freeze
def validate_each(record, attribute, value)
record.errors.add(attribute, message: "Thou shalt not use this username! Please choose another one.") if FORBIDDEN_SCREEN_NAMES.include?(value.downcase)
record.errors.add(attribute, message: "Registration is tempoarily disabled for new users.") if FORBIDDEN_SCREEN_NAME_REGEXPS.any? { |regexp| value.downcase =~ regexp }
end
2015-04-18 13:12:58 -07:00
end