1
0
mirror of https://github.com/whippyshou/mastodon synced 2025-01-24 10:44:00 +09:00
whippy-edition/app/validators/unreserved_validator.rb

16 lines
424 B
Ruby
Raw Normal View History

# 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