mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 14:29:53 +01:00
11 lines
600 B
Ruby
11 lines
600 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ScreenNameValidator < ActiveModel::EachValidator
|
|
FORBIDDEN_SCREEN_NAMES = APP_CONFIG["forbidden_screen_names"].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
|
|
end
|