about summary refs log tree commit diff
path: root/app/validators/unreserved_validator.rb
blob: 4e5b9dafc3c54a7304b7f3c6ecabbb63e15236e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# frozen_string_literal: true

class UnreservedValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return if value.nil?
    record.errors.add(attribute, I18n.t('accounts.reserved_username')) if reserved_username?(value)
  end

  private

  def reserved_username?(value)
    return false unless Setting.reserved_usernames
    Setting.reserved_usernames.include?(value.downcase)
  end
end