2022-01-22 21:32:45 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-09 14:12:52 +01:00
|
|
|
class ScreenNameValidator < ActiveModel::EachValidator
|
2022-01-22 21:32:45 +01:00
|
|
|
FORBIDDEN_SCREEN_NAMES = %w[justask_admin retrospring_admin admin justask retrospring about public
|
2015-01-09 14:12:52 +01:00
|
|
|
notifications inbox sign_in sign_up sidekiq moderation moderator mod administrator
|
2022-01-22 21:32:45 +01: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
|
2015-01-09 14:12:52 +01:00
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
2022-01-22 21:32:45 +01:00
|
|
|
record.errors[attribute] << "Thou shalt not use this username! Please choose another one." if FORBIDDEN_SCREEN_NAMES.include? value.downcase
|
|
|
|
record.errors[attribute] << "Registration is tempoarily disabled for new users." if FORBIDDEN_SCREEN_NAME_REGEXPS.any? { |regexp| value.downcase =~ regexp }
|
2015-01-09 14:12:52 +01:00
|
|
|
end
|
2015-04-18 22:12:58 +02:00
|
|
|
end
|