You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
424 B

  1. # frozen_string_literal: true
  2. class UnreservedValidator < ActiveModel::EachValidator
  3. def validate_each(record, attribute, value)
  4. return if value.nil?
  5. record.errors.add(attribute, I18n.t('accounts.reserved_username')) if reserved_username?(value)
  6. end
  7. private
  8. def reserved_username?(value)
  9. return false unless Setting.reserved_usernames
  10. Setting.reserved_usernames.include?(value.downcase)
  11. end
  12. end